http://acm.hit.edu.cn/hoj/problem/view?id=3120
设a=k1c+p,b=k2c+q
则a-b=(k1-k2)c+(p-q)
"For positive numbers a, b, c where a >= b, it doesn't always hold that ( a mod c) >= ( b mod c)."
所以(a-b) mod c=(c+p-q)%c
#include <stdio.h>
int main()
{
int p,q,c,n;
while (scanf("%d", &n) != EOF)
{
while(n--)
{
scanf("%d %d %d", &p, &q, &c);
printf("%d\n", (c + p - q) % c);
}
}
return 0;
}