#include <bits/stdc++.h>
int main() {
  int querycount;
  scanf("%i", &querycount);
  for (int i = 0; i < querycount; i++) {
    int kidcount;
    int exchanges[200];
    scanf("%i", &kidcount);
    for (int j = 0; j < kidcount; j++) {
      scanf("%i", &exchanges[j]);
      exchanges[j]--;
    }
    for (int j = 0; j < kidcount; j++) {
      int daycount = 0;
      int currkid = j;
      if (exchanges[currkid] == j) {
        daycount = 1;
      } else
        do {
          currkid = exchanges[currkid];
          daycount++;
        } while (currkid != j);
      printf("%i ", daycount);
    }
    putchar('\n');
  }
}
