#include <bits/stdc++.h>
using namespace std;
int a[203];
int main() {
  int q, n;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i) {
      int num = a[i], cnt = 1;
      while (num != i) {
        num = a[num];
        ++cnt;
      }
      printf("%d ", cnt);
    }
    puts("");
  }
  return 0;
}
