#include <bits/stdc++.h>
using namespace std;
vector<int> A(100001);
vector<int> adj[100001];
int cnt = 1;
int nexte;
int findme;
void dfs(int node) {
  if (node == findme) {
    return;
  }
  cnt++;
  for (int next : adj[node]) {
    dfs(next);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> A[i];
    for (int i = 1; i <= n; i++) {
      adj[i].push_back(A[i]);
    }
    for (int i = 1; i <= n; i++) {
      nexte = adj[A[i]].back();
      findme = A[i];
      dfs(nexte);
      cout << cnt << " ";
      cnt = 1;
    }
    cout << endl;
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
    }
  }
}
