#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3 + 9;
ll mod = 1e9L + 9, BASE = 4e6 + 1, mod2 = 2000000011ll, powr[N], pow2[N];
pair<ll, ll> hash_it(vector<ll> &v) {
ll c1 = 0, c2 = 0;
for (int i = 0; i < v.size(); i++) {
c1 = (c1 * BASE + v[i]) % mod;
c2 = (c2 * BASE + v[i]) % mod2;
}
return {c1, c2};
}
void test() {
int n;
scanf("%d", &n);
ll a[4][n], sum = 0;
for (int i = 0; i < 4; i++) for (int j = 0; j < n; j++) scanf("%lld", &a[i][j]), sum += a[i][j];
if (sum % n != 0) {
printf("No\n");
return;
}
sum /= n;
set<pair<ll, ll>> s;
//save rotations of first 2 arrays
for (int st = 0; st < n; st++) {//start idx of second array
vector<ll> v(n);
for (int count = 0; count < n; count++) v[count] = a[0][count] + a[1][(count + st) % n];
s.insert(hash_it(v));
}
//search for matching rotation using the last 2 arrays
bool flag = false;
for (int st = 0; st < n; st++) {//start idx of second array
if (flag)break;//if found answer break
vector<ll> v(n);
for (int count = 0; count < n; count++) v[count] = sum - a[2][count] - a[3][(count + st) % n];
auto c = hash_it(v);
ll c1 = c.first, c2 = c.second;
for (int i = 0; i <= n; i++) {
//search for the current rotation
c1 = (((c1 - v[i] * powr[n - 1]) % mod) + mod) % mod;
c2 = (((c2 - v[i] * pow2[n - 1]) % mod2) + mod2) % mod2;
c1 = (c1 * BASE + v[i]) % mod;
c2 = (c2 * BASE + v[i]) % mod2;
if (s.count({c1, c2}))flag = true;
}
}
if (flag)printf("Yes\n");
else printf("No\n");
}
int main() {
// freopen("input.in", "r", stdin);
int t;
scanf("%d", &t);
powr[0] = pow2[0] = 1;
for (int i = 1; i < N; i++) {
powr[i] = (powr[i - 1] * BASE) % mod;
pow2[i] = (pow2[i - 1] * BASE) % mod2;
}
for (int cas = 1; cas <= t; cas++) {
printf("Case %d: ", cas);
test();
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIGxsI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dICsgYVsxXVsoY291bnQgKyBzdCkgJSBuXTsKICAgICAgICBzLmluc2VydChoYXNoX2l0KHYpKTsKICAgIH0KCiAgICAvL3NlYXJjaCBmb3IgbWF0Y2hpbmcgcm90YXRpb24gdXNpbmcgdGhlIGxhc3QgMiBhcnJheXMKICAgIGJvb2wgZmxhZyA9IGZhbHNlOwogICAgZm9yIChpbnQgc3QgPSAwOyBzdCA8IG47IHN0KyspIHsvL3N0YXJ0IGlkeCBvZiBzZWNvbmQgYXJyYXkKICAgICAgICBpZiAoZmxhZylicmVhazsvL2lmIGZvdW5kIGFuc3dlciBicmVhawogICAgICAgIHZlY3RvcjxsbD4gdihuKTsKICAgICAgICBmb3IgKGludCBjb3VudCA9IDA7IGNvdW50IDwgbjsgY291bnQrKykgdltjb3VudF0gPSBzdW0gLSBhWzJdW2NvdW50XSAtIGFbM11bKGNvdW50ICsgc3QpICUgbl07CgogICAgICAgIGF1dG8gYyA9IGhhc2hfaXQodik7CiAgICAgICAgbGwgYzEgPSBjLmZpcnN0LCBjMiA9IGMuc2Vjb25kOwoKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8PSBuOyBpKyspIHsKICAgICAgICAgICAgLy9zZWFyY2ggZm9yIHRoZSBjdXJyZW50IHJvdGF0aW9uCiAgICAgICAgICAgIGMxID0gKCgoYzEgLSB2W2ldICogcG93cltuIC0gMV0pICUgbW9kKSArIG1vZCkgJSBtb2Q7CiAgICAgICAgICAgIGMyID0gKCgoYzIgLSB2W2ldICogcG93MltuIC0gMV0pICUgbW9kMikgKyBtb2QyKSAlIG1vZDI7CiAgICAgICAgICAgIGMxID0gKGMxICogQkFTRSArIHZbaV0pICUgbW9kOwogICAgICAgICAgICBjMiA9IChjMiAqIEJBU0UgKyB2W2ldKSAlIG1vZDI7CiAgICAgICAgICAgIGlmIChzLmNvdW50KHtjMSwgYzJ9KSlmbGFnID0gdHJ1ZTsKICAgICAgICB9CiAgICB9CiAgICBpZiAoZmxhZylwcmludGYoIlllc1xuIik7CiAgICBlbHNlIHByaW50ZigiTm9cbiIpOwp9CgppbnQgbWFpbigpIHsKLy8gICAgZnJlb3BlbigiaW5wdXQuaW4iLCAiciIsIHN0ZGluKTsKICAgIGludCB0OwogICAgc2NhbmYoIiVkIiwgJnQpOwogICAgcG93clswXSA9IHBvdzJbMF0gPSAxOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBOOyBpKyspIHsKICAgICAgICBwb3dyW2ldID0gKHBvd3JbaSAtIDFdICogQkFTRSkgJSBtb2Q7CiAgICAgICAgcG93MltpXSA9IChwb3cyW2kgLSAxXSAqIEJBU0UpICUgbW9kMjsKICAgIH0KCiAgICBmb3IgKGludCBjYXMgPSAxOyBjYXMgPD0gdDsgY2FzKyspIHsKICAgICAgICBwcmludGYoIkNhc2UgJWQ6ICIsIGNhcyk7CiAgICAgICAgdGVzdCgpOwogICAgfQp9Cg==