// www.hackerearth.com/challenge/competitive/airtel-crack-the-code/algorithm/square-and-cube-2-dd08d321/
#include <bits/stdc++.h>
using namespace std;
const int MAX_VAL = 1e5 + 5;
const int MAX_N = 3e5 + 5;
const int BASE = 100003;
const long long MOD = 1e9 + 7;
int N, Q, A[MAX_N];
int cnt2[MAX_VAL], cnt3[MAX_VAL];
int zero[MAX_N], neg[MAX_N];
long long basepow[MAX_VAL], hash2[MAX_N], hash3[MAX_N];
int lp[MAX_VAL];
vector<int> pr;
vector<int> p2[MAX_VAL];
vector<pair<int, int> > p3[MAX_VAL];
void init() {
for (int i = 2; i < MAX_VAL; i++) {
if (lp[i] == 0) lp[i] = i, pr.push_back(i);
for (int j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] < MAX_VAL; j++)
lp[i * pr[j]] = pr[j];
int j = i;
while (j != 1) {
int cur = lp[j], cnt = 0;
while (lp[j] == cur)
j /= lp[j], cnt++;
if (cnt & 1) p2[i].push_back(cur);
if (cnt % 3) p3[i].emplace_back(cur, cnt % 3);
}
}
basepow[0] = 1;
for (int i = 1; i < MAX_VAL; i++)
basepow[i] = (basepow[i - 1] * BASE) % MOD;
}
void solve() {
for (int i = 1; i <= N; i++) {
zero[i] = zero[i - 1];
neg[i] = neg[i - 1];
hash2[i] = hash2[i - 1];
hash3[i] = hash3[i - 1];
if (A[i] == 0)
zero[i]++;
if (A[i] < 0) {
neg[i]++;
A[i] = -A[i];
}
for (int p : p2[A[i]]) {
hash2[i] = (hash2[i] - cnt2[p] * basepow[p]) % MOD;
cnt2[p] ^= 1;
hash2[i] = (hash2[i] + MOD + cnt2[p] * basepow[p]) % MOD;
}
for (auto &x : p3[A[i]]) {
int p, c; tie(p, c) = x;
hash3[i] = (hash3[i] - cnt3[p] * basepow[p]) % MOD;
cnt3[p] += c; cnt3[p] %= 3;
hash3[i] = (hash3[i] + MOD + cnt3[p] * basepow[p]) % MOD;
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
init();
cin >> N >> Q;
for(int i = 1; i <= N; i++)
cin >> A[i];
solve();
for(int i = 0; i < Q; i++) {
int L, R; cin >> L >> R;
int z, n, c2, c3;
z = zero[R] - zero[L - 1];
n = neg[R] - neg[L - 1];
c2 = hash2[R] - hash2[L - 1];
c3 = hash3[R] - hash3[L - 1];
int ans = (!c3) << 1 | (!c2 && !(n & 1));
if (z) ans = 3;
if (ans == 0) cout << "None";
else if (ans == 1) cout << "Square";
else if (ans == 2) cout << "Cube";
else cout << "Both";
cout << "\n";
}
return 0;
}
Ly8gd3d3LmhhY2tlcmVhcnRoLmNvbS9jaGFsbGVuZ2UvY29tcGV0aXRpdmUvYWlydGVsLWNyYWNrLXRoZS1jb2RlL2FsZ29yaXRobS9zcXVhcmUtYW5kLWN1YmUtMi1kZDA4ZDMyMS8KCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9WQUwgPSAxZTUgKyA1Owpjb25zdCBpbnQgTUFYX04gPSAzZTUgKyA1OwoKY29uc3QgaW50IEJBU0UgPSAxMDAwMDM7CmNvbnN0IGxvbmcgbG9uZyBNT0QgPSAxZTkgKyA3OwoKaW50IE4sIFEsIEFbTUFYX05dOwppbnQgY250MltNQVhfVkFMXSwgY250M1tNQVhfVkFMXTsKaW50IHplcm9bTUFYX05dLCBuZWdbTUFYX05dOwpsb25nIGxvbmcgYmFzZXBvd1tNQVhfVkFMXSwgaGFzaDJbTUFYX05dLCBoYXNoM1tNQVhfTl07CgppbnQgbHBbTUFYX1ZBTF07CnZlY3RvcjxpbnQ+IHByOwp2ZWN0b3I8aW50PiBwMltNQVhfVkFMXTsKdmVjdG9yPHBhaXI8aW50LCBpbnQ+ID4gcDNbTUFYX1ZBTF07CnZvaWQgaW5pdCgpIHsKICAgIGZvciAoaW50IGkgPSAyOyBpIDwgTUFYX1ZBTDsgaSsrKSB7CiAgICAgICAgaWYgKGxwW2ldID09IDApIGxwW2ldID0gaSwgcHIucHVzaF9iYWNrKGkpOwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgcHIuc2l6ZSgpICYmIHByW2pdIDw9IGxwW2ldICYmIGkgKiBwcltqXSA8IE1BWF9WQUw7IGorKykKICAgICAgICAgICAgbHBbaSAqIHByW2pdXSA9IHByW2pdOwogICAgICAgIGludCBqID0gaTsKICAgICAgICB3aGlsZSAoaiAhPSAxKSB7CiAgICAgICAgICAgIGludCBjdXIgPSBscFtqXSwgY250ID0gMDsKICAgICAgICAgICAgd2hpbGUgKGxwW2pdID09IGN1cikKICAgICAgICAgICAgICAgIGogLz0gbHBbal0sIGNudCsrOwogICAgICAgICAgICBpZiAoY250ICYgMSkgcDJbaV0ucHVzaF9iYWNrKGN1cik7CiAgICAgICAgICAgIGlmIChjbnQgJSAzKSBwM1tpXS5lbXBsYWNlX2JhY2soY3VyLCBjbnQgJSAzKTsKICAgICAgICB9CiAgICB9CiAgICBiYXNlcG93WzBdID0gMTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgTUFYX1ZBTDsgaSsrKQogICAgICAgIGJhc2Vwb3dbaV0gPSAoYmFzZXBvd1tpIC0gMV0gKiBCQVNFKSAlIE1PRDsKfQoKdm9pZCBzb2x2ZSgpIHsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IE47IGkrKykgewogICAgICAgIHplcm9baV0gPSB6ZXJvW2kgLSAxXTsKICAgICAgICBuZWdbaV0gPSBuZWdbaSAtIDFdOwogICAgICAgIGhhc2gyW2ldID0gaGFzaDJbaSAtIDFdOwogICAgICAgIGhhc2gzW2ldID0gaGFzaDNbaSAtIDFdOwogICAgICAgIGlmIChBW2ldID09IDApCiAgICAgICAgICAgIHplcm9baV0rKzsKICAgICAgICBpZiAoQVtpXSA8IDApIHsKICAgICAgICAgICAgbmVnW2ldKys7CiAgICAgICAgICAgIEFbaV0gPSAtQVtpXTsKICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgcCA6IHAyW0FbaV1dKSB7CiAgICAgICAgICAgIGhhc2gyW2ldID0gKGhhc2gyW2ldIC0gY250MltwXSAqIGJhc2Vwb3dbcF0pICUgTU9EOwogICAgICAgICAgICBjbnQyW3BdIF49IDE7CiAgICAgICAgICAgIGhhc2gyW2ldID0gKGhhc2gyW2ldICsgTU9EICsgY250MltwXSAqIGJhc2Vwb3dbcF0pICUgTU9EOwogICAgICAgIH0KICAgICAgICBmb3IgKGF1dG8gJnggOiBwM1tBW2ldXSkgewogICAgICAgICAgICBpbnQgcCwgYzsgdGllKHAsIGMpID0geDsKICAgICAgICAgICAgaGFzaDNbaV0gPSAoaGFzaDNbaV0gLSBjbnQzW3BdICogYmFzZXBvd1twXSkgJSBNT0Q7CiAgICAgICAgICAgIGNudDNbcF0gKz0gYzsgY250M1twXSAlPSAzOwogICAgICAgICAgICBoYXNoM1tpXSA9IChoYXNoM1tpXSArIE1PRCArIGNudDNbcF0gKiBiYXNlcG93W3BdKSAlIE1PRDsKICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUoTlVMTCk7CiAgICBpbml0KCk7CiAgICAKICAgIGNpbiA+PiBOID4+IFE7CiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IE47IGkrKykKICAgICAgICBjaW4gPj4gQVtpXTsKCiAgICBzb2x2ZSgpOwogICAgICAgIAogICAgZm9yKGludCBpID0gMDsgaSA8IFE7IGkrKykgewogICAgICAgIGludCBMLCBSOyBjaW4gPj4gTCA+PiBSOwogICAgICAgIGludCB6LCBuLCBjMiwgYzM7CiAgICAgICAgeiA9IHplcm9bUl0gLSB6ZXJvW0wgLSAxXTsKICAgICAgICBuID0gbmVnW1JdIC0gbmVnW0wgLSAxXTsKICAgICAgICBjMiA9IGhhc2gyW1JdIC0gaGFzaDJbTCAtIDFdOwogICAgICAgIGMzID0gaGFzaDNbUl0gLSBoYXNoM1tMIC0gMV07CiAgICAgICAgaW50IGFucyA9ICghYzMpIDw8IDEgfCAoIWMyICYmICEobiAmIDEpKTsKICAgICAgICBpZiAoeikgYW5zID0gMzsKCiAgICAgICAgaWYgKGFucyA9PSAwKSBjb3V0IDw8ICJOb25lIjsKICAgICAgICBlbHNlIGlmIChhbnMgPT0gMSkgY291dCA8PCAiU3F1YXJlIjsKICAgICAgICBlbHNlIGlmIChhbnMgPT0gMikgY291dCA8PCAiQ3ViZSI7CiAgICAgICAgZWxzZSBjb3V0IDw8ICJCb3RoIjsKICAgICAgICBjb3V0IDw8ICJcbiI7CiAgICB9CiAgICAKICAgIHJldHVybiAwOwp9