#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 11;
bitset<N> a[2][N];
char buf[N];
int main()
{
    int T, n;
    scanf("%d", &T);
    while (T--)
    {
        memset(a, 0, sizeof(a));
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
        {
            scanf("%s", buf);
            for (int j = 0; j < n; j++)
            {
                if (buf[j] == 'P') a[0][i].set(j);
                if (buf[j] == 'Q') a[1][i].set(j);
            }
        }
        bool flag = true;
        for (int k = 0; k < 2 && flag; k++)
            for (int i = 0; i < n && flag; i++)
                for (int j = 0; j < n && flag; j++)
                    if (a[k][i][j] && (a[k][i] | a[k][j]) != a[k][i])
                        flag = false;
        puts(flag ? "T" : "N");
    }
    return 0;
}