#include <bits/stdc++.h>
using namespace std;
int a[305];
int ans[305];
void dfs(int x, int now) {
  ans[now]++;
  if (a[x] == now)
    return;
  else
    dfs(a[x], now);
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int n;
    memset(ans, 0, sizeof(ans));
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
      dfs(i, i);
    }
    for (int i = 1; i <= n; i++) {
      printf("%d ", ans[i]);
    }
    printf("\n");
  }
}
