#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<long long> a;
    a.push_back(0);
    long long tmp;
    for (int i = 0; i < (int)(n); ++i) {
      cin >> tmp;
      a.push_back(tmp);
    }
    for (int i = 1; i <= (int)(n); i++) {
      int step = 0, pos = i;
      while (a[pos] != i) {
        pos = a[pos];
        step++;
      }
      cout << step + 1 << " ";
    }
    cout << endl;
  }
  return 0;
}
