#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<class T>
void read(T& x)
{
	T res = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {
		if (c == '-')f = -1; c = getchar();
	}
	while (isdigit(c)) {
		res = (res << 3) + (res << 1) + c - '0'; c = getchar();
	}
	x = res * f;
}
const ll N = 20000000 + 10;
#define int long long 
int prime[N/5],tnum[N];
bool fprime[N];
void init(int n)
{
	for (int i = 2; i <= n; i++)
	{
		if (!fprime[i])prime[++prime[0]] = i;
		for (int j = 1; j <= prime[0] && prime[j] * i <= n; j++)
		{
			fprime[i * prime[j]] = 1;
			if (i % prime[j] == 0)break;
		}
	}
	for (int i = 1; i <= prime[0]; i++)
	{
		for (int j = 1;prime[i] * j <= n; j++)
			tnum[prime[i] * j]++;
	}
	//tnum[1] = 1;
}
int work(int x)
{
	return 1ll << (tnum[x]);
}
signed main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
#endif // ONLINE_JUDGE
	init(2e7);
	int t; read(t);
	while (t--)
	{
		int c, d, x;
		ll ans = 0;
		read(c), read(d), read(x);
		for (int i = 1; i * i <= x; i++)
		{
			if (x % i)continue;
			if ((x / i + d) % c == 0)
				ans += work((x / i + d) / c);
			if (((i + d) % c == 0)&&(i*i!=x))
				ans += work((i + d) / c);
		}
		printf("%lld\n", ans);
	}
	return 0;
}
