#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) {
      int count = 1;
      int j = i;
      while (1) {
        int rem = p[j];
        if (i == rem) break;
        count++;
        j = rem;
      }
      cout << count << " ";
    }
    cout << endl;
  }
}
