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