#include<bits/stdc++.h>
using namespace std;
#define T int t; cin >> t; while(t--)
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> pii;

const int N = 20000005;

vector<int> nxt(N, 1);
vector<int> dp(N, 1);

void prec() {
	dp[1] = 0;
	for (int i = 2; i < N; i++) {
		if (nxt[i] > 1) {
			dp[i] = dp[i/nxt[i]] + (nxt[i/nxt[i]] != nxt[i]);
			continue;
		}
		nxt[i] = i;
		if (i > N/i) continue;
		for (int j = i*i; j < N; j+=i)
			if (nxt[j] == 1) nxt[j] = i;
	}
}

void solve() {
	int c, d, x; cin >> c >> d >> x;
	ll ans = 0;
	for (int i = 1; i*i <= x; i++) {
		if (x%i) continue;
		int k1 = x/i+d;
		if (k1%c==0) ans += 1<<dp[k1/c];
		if (i*i == x) continue;
		int k2 = i+d;
		if (k2%c==0) ans += 1<<dp[k2/c];
	}
	cout << ans << '\n';
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << setprecision(12);
	prec();
	T solve();
	return 0;
}