#include <bits/stdc++.h>
using namespace std;
// Complete the sum function which gives the sum of all elements in a vector regardless of its dimensions
// Trying to use sum function without any input gives following output: "LoL F@$&#^"
int sum (vector< vector<int> >v){
vector< vector<int> >a(v.size());
int s = 0;
for (int i=0; i<v.size();i++){
for (int j=0; j<v[i].size(); j++){
s += v[i][j];
}
}
return s;
}
int sum (vector<int>v){
vector<int>a(v.size());
int s=0;
for (int i=0; i<v.size(); i++){
s += v[i];
}
return s;
}
string sum (){
string s = "LoL F@$&#^";
return s;
}
int main() {
int t;
cin>>t;
while (t--){
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
int r,c;
cin>>r>>c;
vector< vector<int> >b(r);
for (int i=0; i<r; i++){
b[i].resize(c);
for(int j=0;j<c;j++){
cin>>b[i][j];
}
}
cout<<sum(a)<<endl;
cout<<sum(b)<<endl;
cout<<sum()<<endl;
cout<<sum()<<endl;
cout<<sum()<<endl;
}
return 0;
}