#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, k, l, m, n, q, cnt, ke;
  cin >> q;
  while (q--) {
    cin >> n;
    long long a[n + 10];
    map<long long, long long> MP;
    for (i = 0; i < n; i++) cin >> a[i], MP[i + 1] = a[i];
    for (i = 1; i <= n; i++) {
      cnt = 0;
      ke = i;
      l = i;
      while (MP[l] != ke) {
        cnt++;
        l = MP[l];
      }
      cout << cnt + 1 << " ";
    }
    cout << '\n';
  }
}
