/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author kant97
 */

#include <iostream>
#include <fstream>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>

#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>

#ifndef CONTESTS_CPP_MY_ALIASES_HPP
#define CONTESTS_CPP_MY_ALIASES_HPP

#include <utility>
#include <cstdint>


#include <limits>

using pii = std::pair<int, int>;
using pll = std::pair<int64_t, int64_t>;
using pli = std::pair<int64_t, int>;
using tiii = std::tuple<int, int, int>;
using ui = uint32_t;
using ll = int64_t;
using ull = uint64_t;
#if __x86_64__ && __GNUG__
using int128 = __int128;
using uint128 = unsigned __int128;
#else
using int128 = ll;
using uint128 = ull;
#endif
using vc = std::vector<char>;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;

#define fori(n) for (int i = 0; (i) < (int) (n); ++i)
#define forj(n) for (int j = 0; (j) < (int) (n); ++j)
#define rofi(n) for (int i = (int) (n); (i) >= 0; --i)
#define rofj(n) for (int j = (int) (n); (j) >= 0; --j)
#define forn(i, n) for(int i = 0; i < (int) (n); ++i)
#define fore(i, l, r) for(int i = (int) (l); i < (int) (r); ++i)
#define sqr(x) ((x)*(x))
#define pow2(x) ((ull)1 << static_cast<uint64_t>(x))
#define div2k(x, k) (static_cast<uint64_t>(x) >> static_cast<uint64_t>(k))
#define div2(x) div2k(x, 1ULL)
#define divUP(a, b) ((a)+(b)-1)/(b)
#define lowest_significant_bit(x) (static_cast<ull>(x) & -static_cast<ull>(x))
#define count_set_bits(x) __builtin_popcountll(static_cast<ull>(x))
#define sz(x) (static_cast<int>((x).size()))
#define is_odd(x) static_cast<bool>(static_cast<uint64_t>(x) & 1ULL)
#define is_even(x) (!(is_odd(x)))
#define have_diff_parity(x, y) static_cast<bool>(is_odd(x) ^ is_odd(y))
#define have_same_parity(x, y) (!(have_diff_parity(x, y)))
#define All(x) (x).begin(), (x).end()
#define ENDL "\n"
#define FOR_ALL_TEST_CASES int MyTestCaseCounter; in >> MyTestCaseCounter; while(MyTestCaseCounter--)

#endif //CONTESTS_CPP_MY_ALIASES_HPP

#ifndef CONTESTS_CPP_FACTORIZATION_HPP
#define CONTESTS_CPP_FACTORIZATION_HPP

#include <type_traits>


template<typename T>
static inline std::vector<T> get_all_dividers(T n) {
    std::vector<T> all_dividers;
    for (T i = 1; sqr(i) <= n; i++) {
        if (n % i == 0) {
            all_dividers.push_back(i);
            if (sqr(i) != n) all_dividers.push_back(n / i);
        }
    }
    return all_dividers;
}

static inline std::vector<pli> factorize(ll n) {
    std::vector<pli> ans;
    for (ll i = 2; sqr(i) <= std::abs(n); i++) {
        if (n % i == 0) {
            int p = 0;
            do {
                n /= i;
                p++;
            } while (n % i == 0);
            ans.emplace_back(i, p);
        }
    }
    if (std::abs(n) != 1) ans.emplace_back(n, 1);
    return ans;
}

#endif //CONTESTS_CPP_FACTORIZATION_HPP


namespace {
    const int N = 2e7 + 10;
}

class DTheNumberOfPairs {

    vi number_prime_divisors;

    void sieve() {
        number_prime_divisors.resize(N, 0);
        int p = 2;
        for (; sqr(p) < N; ++p)
            if (number_prime_divisors[p] == 0)
                for (int i = p; i < N; i += p)
                    number_prime_divisors[i]++;
        for (; p < N; ++p)
            if (number_prime_divisors[p] == 0)
                for (int i = p; i < N; i += p)
                    number_prime_divisors[i]++;
    }

public:

    void solve(std::istream &in, std::ostream &out) {
        sieve();
        FOR_ALL_TEST_CASES {
            ll c, d, x;
            in >> c >> d >> x;
            vll divisors = get_all_dividers(x);
            ll ans = 0;
            for (ll gcd : divisors) {
                ll k = d * gcd + x;
                if (k % c == 0) {
                    ll k1 = k / c;
                    if (k1 % gcd != 0) continue;
                    ll a1b1 = k1 / gcd;
                    ans += (ll) pow2(number_prime_divisors[a1b1]);
                }
            }
            out << ans << ENDL;
        }
    }

    bool _my_clever_check(std::istream &input, std::istream &juryAnswer, std::istream &myAnswer) {
        return false;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    DTheNumberOfPairs solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    fflush(stdout);
    return 0;
}
