#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int q, n;
  cin >> q;
  while (q--) {
    cin >> n;
    vector<int> ar(n + 1);
    for (int i = 1; i <= n; i++) cin >> ar[i];
    vector<int> ans;
    for (int i = 1; i <= n; i++) {
      if (ar[i] == i) {
        ans.push_back(1);
      } else {
        int cnt = 0, j = ar[i];
        while (true) {
          if (ar[j] == i) {
            cnt++;
            break;
          } else {
            j = ar[j];
            cnt++;
          }
        }
        cnt++;
        ans.push_back(cnt);
      }
    }
    for (int i = 0; i < ans.size(); i++)
      cout << ans[i] << " \n"[i == ans.size() - 1];
    ans.clear();
  }
  return 0;
}
