#include <bits/stdc++.h>
using namespace std;

int t, c, d, x;
vector<int> divis;
int cnt[(int)2e7 + 10];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	for (int i = 2; i <= 2e7; i++) {
		if (cnt[i]) continue;
		for (int j = i; j <= (int)2e7; j += i) {
			cnt[j]++;
		}
	}
	cin >> t;
	while (t--) {
		cin >> c >> d >> x;
		for (int i = 1; i * i <= x; i++) {
			if (x % i) continue;
			divis.push_back(i);
			if (i * i != x) divis.push_back(x / i);
		}
		long long ans = 0;
		for (int i : divis) {
			int prod = x / i + d;
			if (prod % c) continue;
			prod /= c;
			ans += (1LL << cnt[prod]);
		}
		cout << ans << '\n';
		divis.clear();
	}
}