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