#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
//#include <cmath>
//#include <numeric>
//#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> II;

#define MAXP 20000000
int lp[MAXP+1];  // lp[n] = least prime divisor of n
vector<int> primes;
void sieve() {
   for (int i = 2; i <= MAXP; ++i) {
      if (lp[i] == 0) {
         lp[i] = i;
         primes.push_back(i);
      }
      for (int p : primes) {
         if (p > lp[i] || i * p > MAXP) break;
         lp[i * p] = p;
      }
   }
}


int gcd(int a, int b) {
   if (a < 0) a = -a;
   if (b < 0) b = -b;
   if (a < b) swap(a, b);
   while (b > 0) {
      int t = b;
      b = a % b;
      a = t;
   }
   return a > 0 ? a : 1;
}

int lcm(int a, int b) {
   return a / gcd(a,b) * b;
}

namespace BF {

llong solve(llong c, llong d, llong x, bool trace = false) {
   llong res = 0;
   FOR(a, 1, x*x) {
      FOR(b, a, x*x) {
         llong l = lcm(a, b);
         llong g = gcd(a, b);
         if (c * l - d * g == x) {
            int add = a != b ? 2 : 1;
            if (a != b)
            if (trace)
               DEBUG(a, b, g, l, add);
            res += add;
         }
      }
   }
   return res;
}

}

namespace Div {

int count_prime_factors(int n) {
   int res = 0, lastp = 0;
   while (n > 1) {
      int p = lp[n];
      if (p != lastp)
         ++res;
      n /= p;
      lastp = p;
   }
   return res;
}

llong solve(llong c, llong d, llong x, bool trace = false) {
   llong res = 0;

   for (int div = 1; div*div <= x; ++div) {
      if ((x % div) != 0) continue;
      int odiv = x / div;
      VI divisors = { div };
      if (odiv != div)
         divisors.push_back(odiv);
      for (int g : divisors) {
         llong right_side = x + d * g;
         if ((right_side % c) == 0) {
            llong l = right_side / c;
            if (l % g == 0) {
               llong rem = l / g;
               if (rem > MAXP) {
                  DEBUG(c, d, x, g, l, rem);
                  assert(false);
               }
               int npfactors = count_prime_factors(rem);
               llong add = 1LL << npfactors;
               if (trace) DEBUG(g, l, rem, add);
               res += add;
            }
         }
      }
   }

   return res;
}

}


int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   sieve();

   int TC;
   cin >> TC;
   FOR(tc, 1, TC) {
      int c, d, x;
      cin >> c >> d >> x;
      llong res = Div::solve(c, d, x);
      /*
      if (x < 100) {
         llong resBF = BF::solve(c, d, x, true);
         DEBUG(res, resBF);
         assert(res == resBF);
      }
      */
      cout << res << '\n';
   }

   return 0;
}
