#include <iostream>
using namespace std;
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
int main() {
int t;
cin >> t;
while (t -- ) {
int a0, a1, b0, b1;
cin >> a0 >> a1 >> b0 >> b1;
int cnt = 0;
for (int i = 1; i * i <= b1; i ++ )
if (b1 % i == 0) {
if (i % a1 == 0 && gcd(i / a1, a0 / a1) == 1 && gcd(b1 / b0, b1 / i) == 1)
cnt ++ ;
if (i * i != b1) {
int I = b1 / i;
if (I % a1 == 0 && gcd(I / a1, a0 / a1) == 1 && gcd(b1 / b0, b1 / I) == 1)
cnt ++ ;
}
}
cout << cnt << endl;
}
return 0;
}
#include <iostream>
using namespace std;
const int N = 1e6 + 10;
int H_number[N];
void init(int n) {
for (int i = 5; i <= 1e6 + 1; i += 4) {
for (int j = 5; j <= 1e6 + 1; j += 4) {
int x = i * j;
if (x > N)
break;
if (H_number[i] == 0 && H_number[j] == 0)
H_number[x] = 1;
else
H_number[x] = -1;
}
}
int cnt = 0;
for (int i = 0; i <= 1e6 + 1; i ++ ) {
if (H_number[i] == 1)
cnt ++ ;
H_number[i] = cnt;
}
}
int main() {
init(N);
int n;
while (cin >> n && n) {
printf("%d %d\n", n, H_number[n]);
}
return 0;
}
#include <iostream>
using namespace std;
typedef long long LL;
int qmi(int a, int k, int p) {
int res = 1 % p;
while (k) {
if (k & 1)
res = (LL)res * a % p;
a = (LL)a * a % p;
k >>= 1;
}
return res;
}
int main() {
int n, m, k, x;
cin >> n >> m >> k >> x;
int X = qmi(10, k, n);
printf("%d\n", (x + m * X) % n);
return 0;
}