1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include<bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << ": " << (x) << endl #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define dwn(i,a,b) for(int i=(a);i>=(b);i--) #define SZ(a) ((int) (a).size())
#define vi vector<int> #define pb push_back #define all(x) (x).begin(), (x).end() #define x first #define y second using pii = pair<int, int>; using ll = long long;
void solve(){ int n; cin>>n; vector<vi> w(n+1, vi(n+1)); rep(i, 1, n) rep(j, 1, n) cin>>w[i][j]; int res=0; auto upd=[&](int x, int y) -> void{ res^=w[x][y]; }; auto OK=[&](int x, int y) -> bool{ return x>=1 && x<=n && y>=1 && y<=n; }; for(int val=1; val<=n/2; val+=2){ for(int x=val, y=val; OK(x, y); x+=2, y-=2){ upd(x, y); upd(x, n+1-y); } for(int x=val-2, y=val+2; OK(x, y); x-=2, y+=2){ upd(x, y); upd(x, n+1-y); } } for(int val=n-1; val>n/2; val-=2){ for(int x=val+1, y=val-1; OK(x, y); x+=2, y-=2){ upd(x, y); upd(x, n+1-y); } for(int x=val-1, y=val+1; OK(x, y); x-=2, y+=2){ upd(x, y); upd(x, n+1-y); } } cout<<res<<"\n"; }
signed main(){ ios::sync_with_stdio(false); int cs; cin>>cs; while(cs--) solve(); return 0; }
|