#include <bits/stdc++.h>
using namespace std;

// Speed
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// Typedefs
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define endl '\n'
#define yes cout << "yes\n"
#define no cout << "no\n"

// Loops
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)
#define each(x, a) for (auto& x : a)

// Consts
const int INF = 1e18;
const int MOD = 1e9+7;
const int N = 2e5 + 5;

// Math
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }

int power(int a, int b, int m = MOD) {
    int res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int modinv(int a, int m = MOD) {
    return power(a, m - 2, m);
}

// Logic
void solve() {
    // Code
    int ans = 0;

for (int i = 0; i < 10; i++) {
    string s;
    cin >> s;

    for (int j = 0; j < 10; j++) {
        if (s[j] == 'X') {
            ans += min({i, j, 9 - i, 9 - j}) + 1;
        }
    }
}

cout << ans << '\n';
    
}

// Main
int32_t main() {
    fast_io;

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
