#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using P = pair<i64, i64>;
void solve() {
  i64 n;
  cin >> n;
  vector<i32> g(n);
  for (i32 i = 0; i < (i32)(n); i++) {
    i32 k;
    cin >> k;
    g[i] = k - 1;
  }
  vector<i32> ans;
  for (i32 i = 0; i < (i32)(n); i++) {
    i32 now = -1;
    i32 cnt = 0;
    while (now != i) {
      cnt++;
      if (now == -1) now = i;
      now = g[now];
    }
    ans.emplace_back(cnt);
  }
  for (i32 i = 0; i < (i32)(n); i++) {
    cout << ans[i] << " \n"[i == n - 1];
  }
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  i64 q;
  cin >> q;
  for (i32 i = 0; i < (i32)(q); i++) solve();
}
