#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, n, p[205];
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i < n; i++) {
      int m = p[i], ans = 1;
      while (m != i) {
        ans++;
        m = p[m];
      }
      cout << ans << " ";
    }
    int m = p[n], ans = 1;
    while (m != n) {
      ans++;
      m = p[m];
    }
    cout << ans << endl;
  }
  return 0;
}
