#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int n;
    cin >> n;
    int perm[n];
    for (int j = 0; j < n; j++) {
      cin >> perm[j];
      perm[j]--;
    }
    for (int j = 0; j < n; j++) {
      int day = 1;
      int curr_student = j;
      int traversal_student = j;
      for (int k = 0; k < 200; k++) {
        traversal_student = perm[traversal_student];
        if (traversal_student == curr_student) {
          break;
        }
        day++;
      }
      cout << day << " ";
    }
    cout << endl;
  }
  return 0;
}
