#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], b[n], i, j, k;
    for (i = 1; i <= n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    for (i = 1; i <= n; i++) {
      int c = 1;
      while (b[i] != i) {
        b[i] = a[b[i]];
        c++;
      }
      cout << c << " ";
    }
    cout << "\n";
  }
}
