#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

int cnt[10][10];
int main() {
	int n; scanf("%d", &n);
	rep(t, n) {
		memset(cnt, 0, sizeof(cnt));
		vector<P>v;
		rep(i, 10)rep(j, 10) {
			int d; scanf("%d", &d);
			if (!d)continue;
			cnt[i][j]++;

			rep(k, 4) {
				int nx = i + dx[k], ny = j + dy[k];
				if (0 <= nx&&nx < 10 && 0 <= ny&&ny < 10)cnt[nx][ny]++;
			}
		}
	}
}