#include <bits/stdc++.h>
using namespace std;
const int N = 2e2 + 10;
int t, n, a[N], ans[N];
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int k = i, t = a[i], cnt = 0;
    while (t - 1 != i) {
      cnt++;
      k = t - 1;
      t = a[k];
    }
    ans[i] = ++cnt;
  }
  for (int i = 0; i < n; i++) cout << ans[i] << ' ';
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) solve();
}
