#include <stdio.h>
#include <iostream>
using namespace std;
#define ull unsigned long long
int quick_pow(int a, int n, int m) {
ull r = 1, p = a % m;
for (; n > 0; n /= 2) {
if (n % 2 == 1)
r = (r * p) % m;
p = (p * p) % m;
}
return r;
}
int main() {
int t;
scanf("%d", &t);
ull a, b, c, p, D, tmp;
for (int k = 0; k < t; k++) {
scanf("%llu %llu %llu %llu", &a, &b, &c, &p);
D = ((b*b % p) - (4*(a*c % p) % p) + p) % p;
if (D == 0)
printf("YES\n");
else {
tmp = quick_pow(D,(p-1)/2, p);
if (tmp == 1)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSB1bGwgdW5zaWduZWQgbG9uZyBsb25nCgppbnQgcXVpY2tfcG93KGludCBhLCBpbnQgbiwgaW50IG0pIHsKCXVsbCByID0gMSwgcCA9IGEgJSBtOwoJZm9yICg7IG4gPiAwOyBuIC89IDIpIHsKCQlpZiAobiAlIDIgPT0gMSkKCQkJciA9IChyICogcCkgJSBtOwoJCXAgPSAocCAqIHApICUgbTsKCX0KCXJldHVybiByOwp9CgppbnQgbWFpbigpIHsKCWludCB0OwoJc2NhbmYoIiVkIiwgJnQpOwoJdWxsIGEsIGIsIGMsIHAsIEQsIHRtcDsKCWZvciAoaW50IGsgPSAwOyBrIDwgdDsgaysrKSB7CgkJc2NhbmYoIiVsbHUgJWxsdSAlbGx1ICVsbHUiLCAmYSwgJmIsICZjLCAmcCk7CgkJRCA9ICgoYipiICUgcCkgLSAoNCooYSpjICUgcCkgJSBwKSArIHApICUgcDsKCQlpZiAoRCA9PSAwKQoJCQlwcmludGYoIllFU1xuIik7CgkJZWxzZSB7CgkJCXRtcCA9IHF1aWNrX3BvdyhELChwLTEpLzIsIHApOwoJCQlpZiAodG1wID09IDEpCgkJCQlwcmludGYoIllFU1xuIik7CgkJCWVsc2UKCQkJCXByaW50ZigiTk9cbiIpOwoJCX0KCX0KCXJldHVybiAwOwp9