#include <bits/stdc++.h>
using namespace std;
int n, nex[505];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> nex[i];
    for (int i = 1; i <= n; ++i) {
      int res = 1, u = i;
      while (nex[u] != i) {
        u = nex[u];
        res++;
      }
      cout << res << " ";
    }
    cout << "\n";
  }
  return 0;
}
