#include #include #include #include using namespace std; typedef long long ll; const ll INF = 0x3f3f3f3f; const ll N = 1e3 + 10; int mat[N][N]; ll ans[N][N]; struct node { int root; ll add; } line[N], cal[N]; int main() { int t; cin>>t; while(t--) { int n, m, q; scanf("%d%d%d", &n, &m, &q); for(int i = 0; i