#include <bits/stdc++.h>
using namespace std;
long long step, awal, arr[250];
void simulasi(int n) {
  step++;
  if (awal != arr[n]) simulasi(arr[n]);
}
int main() {
  long long x, n, i, ii;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    for (ii = 1; ii <= x; ii++) {
      cin >> arr[ii];
    }
    for (ii = 1; ii <= x; ii++) {
      step = 0;
      awal = ii;
      simulasi(ii);
      cout << step;
      if (ii == x)
        cout << endl;
      else
        cout << " ";
    }
  }
}
