#include <bits/stdc++.h>

#define MAXN 20000003
#define ll long long
using namespace std;

ll res[100];
int fac[MAXN];//用来存储数字i的因数个数
int cnt[MAXN];//用来存储数字i最小素因子的幂次
int prime[MAXN] = {0};
ll ans;
ll c,d,x;
void cal(ll x)
{
    ans += res[fac[x]];
    return ;
}
void work(ll k)
{
    if((k + d) % c != 0)
        return ;
    ll b = (k + d) / c;
    cal(b);
    //printf("T%lld %lld %d %lld\n",x / k,b,fac[b],ans);
}
void init() {
    for (int i = 2; i <= MAXN; i++) {
        if (!prime[i]) {//如果是素数我们让它的因数个数为2
            prime[++prime[0]] = i;
            fac[i] = 1;
            cnt[i] = 1;//素数的最小素因数是它自己;
        }
        for (int j = 1; j <= prime[0]; j++) {
           	if (prime[j] * i > MAXN) break;
            prime[prime[j] * i] = 1;//利用素因数标记;
            if (i % prime[j] == 0) {
                fac[i * prime[j]] = fac[i];
                cnt[i * prime[j]] = cnt[i] + 1;//这个数的最小幂次更新为合因子的最小次幂加1;
                break;
            }
            else { // 当这个素是两个互素的数标记时
                fac[i * prime[j]] = fac[i] + 1;
                cnt[i * prime[j]] = 1;
            }
        }
    }
    fac[1] = 0;
    res[0] = 1ll;
    for(int i = 1;i <= 64;i++)
        res[i] = res[i - 1] * 2ll;
    return ;
}

int main()
{
    int T;
    init();
    scanf("%d",&T);
    while(T--)
    {
        ans = 0;
        scanf("%lld%lld%lld",&c,&d,&x);
        for(int i = 1;i <= x / i;i++)
            if(x % i == 0)
            {
                work(x / i);
                if(x / i != i)
                    work(i);
            }
        printf("%lld\n",ans);
    }
    return 0;
}
