#include <stdio.h>
#include <stdlib.h>
#define INPUT_FILE "euclid3.in"
#define OUTPUT_FILE "euclid3.out"
FILE *fin = NULL;
FILE *fout = NULL;
FILE *openfile(char *filename, char *type)
{
FILE *fin = NULL;
if ((fin = fopen(filename, type)) == NULL)
{
printf("fisierul nu a putut sa fie deschis");
exit(EXIT_FAILURE);
}
return fin;
}
void euclid_extins(int *x, int *y, int a, int b, int *d)
{
if (!b)
{
*x = 1;
*y = 0;
*d = a;
}
else
{
// int x0, y0;
// euclid_extins(&x0, &y0, b, a % b, d);
// *x = y0;
// *y = x0 - (a / b) * y0;
euclid_extins(x, y, b, a % b, d);
int aux = *x;
*x = *y;
*y = aux - *y * (a / b);
}
}
int main()
{
fin = openfile(INPUT_FILE, "r");
fout = openfile(OUTPUT_FILE, "w");
int T;
fscanf(fin, "%d", &T);
int a, b, c, d = 0;
int x = 0, y = 0;
for (int i = 0; i < T; i++)
{
// fprintf(fout, "%d ", i);
fscanf(fin, "%d %d %d", &a, &b, &c);
// printf("\n%d %d %d %d %d %d\n", x, y, a, b, c, d);
euclid_extins(&x, &y, a, b, &d);
if (c % d)
{
fprintf(fout, "0 0\n");
}
else
{
fprintf(fout, "%d %d\n", x * (c / d), y * (c / d));
}
}
return 0;
}