#include <bits/stdc++.h>
using namespace std;
int a[205], vis[205];
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int j = i, ans = 0;
    while (a[j] != i) j = a[j], ans++;
    cout << ans + 1 << ' ';
  }
  cout << endl;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
