#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> P(n);
    for (auto& x : P) cin >> x;
    for (auto& x : P) x--;
    for (auto& x : P)
      for (auto [y, template__flag] = make_pair((x), true); template__flag;
           template__flag = false) {
        int count = 0;
        do {
          y = P[y];
          count++;
        } while (y != x);
        cout << count << " ";
      }
    cout << "\n";
  }
}
