#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], res[N];
int n, t;
void check(int haha, int now, int cnt) {
  if (haha == now) {
    res[haha] = cnt;
    return;
  }
  check(haha, a[now], cnt + 1);
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) check(i, a[i], 1);
    for (int i = 1; i <= n; i++) {
      if (i == n)
        cout << res[i] << endl;
      else
        cout << res[i] << " ";
    }
  }
  return 0;
}
