// Created by Nikolay Budin

#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "testlib.h"
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;

const int MAXT = 10'000;
const int MAX_AREA = 1'000'000;

int main(int argc, char* argv[]) {
	registerValidation(argc, argv);

	int t = inf.readInt(1, MAXT, "t");
	inf.readEoln();

	ll sum_area = 0;

	for (int tn = 1; tn <= t; ++tn) {
		setTestCase(tn);
		int n = inf.readInt(1, MAX_AREA, "n");
		inf.readSpace();
		int m = inf.readInt(1, MAX_AREA, "m");
		inf.readEoln();
		sum_area += (ll) n * m;
		for (int i = 0; i < n; ++i) {
			inf.readLine(format("[.#]{%d}", m), format("line %d", i + 1));
		}
	}

	ensure(sum_area <= MAX_AREA);

	inf.readEof();

	return 0;
}