#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--) { int n,m,i,j,l=0; cin>>m>>n; unsigned long long int a[m][n],v; cin>>v; for(i=0;i<m;i++) { for(j=0;j<n;j++) { cin>>a[i][j]; } } for(int k=0;k<m+n-1;k++) { int d; if(k<n) { d=0; } else { d=k-n+1; } if(k%2!=0) { for(j=d;j<=k-d;j++) { if(a[j][k-j]==v) { cout<<a[j][k-j]; l=1; break; } else { cout<<a[j][k-j]<<", "; } } } else { for(j=k-d;j>=d;j--) { if(a[j][k-j]==v) { cout<<a[j][k-j]; l=1; break; } else { cout<<a[j][k-j]<<", "; } } } if(l==1) { break; } } cout<<"\n"; } }
1 5 5 20 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