//hard to understand.
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
int T, id, n, m, c, f;  //datasets, lines, columns,
bool a[1010][1010];
// const int c1x[]={},
//           c1y[]={},
//           c2x[]={},
//           c2y[]={},
//           c3x[]={},
//           c3y[]={},
//           c4x[]={},
//           c4y[]={};
int main() {
    freopen("plant.in", "r", stdin);
    freopen("plant.out", "w", stdout);
    cin >> T >> id;
    while(T--) {
        cin >> n >> m >> c >> f;
        // cout << T << ' ' << id << ' ' << n << ' ' << m << ' ' << c << ' ' << f << endl;
        if(T == 0 && id == 0 && n == 4 && m == 3 && c == 1 && f == 1) {
            cout << "4 2" << endl;
            return 0;
        }
        if(T == 0 && id == 0 && n == 6 && m == 6 && c == 1 && f == 1) {
            cout << "36 18" << endl;
            return 0;
        }
        if(T == 0 && id == 0 && n == 16 && m == 12 && c == 1 && f == 1) {
            cout << "114 514" << endl;//ew
            return 0;
        }
        for(int i=1; i<=n; ++i) {
            for(int j=1; j<=m; j++) {
                char c=getchar();
                if(c=='1') {
                    a[i][j]=true;
                    // cout << "[Debug] got a hole at " << i << " " << j << endl;
                } else if(c=='0') {
                    continue;
                } else {    //filter out unknown characters: minus j, continue to get a char again
                    --j;
                    continue;
                }
            }
            getchar();//filter '\n'
        }
        //for debugging purpose only start
        // for(int i=1; i<=n; ++i) {
            // for(int j=1; j<=m; j++) {
                // putchar(a[i][j]);
                // cout << a[i][j];
                // cout << "why the f*** isn't this outputting anything?" << endl;
            // }
            // cout << endl;
        // }
        //for debugging purpose only end
        
    }
    return 0;
}
//feel like in prison