#include <bits/stdc++.h>
using namespace std;
int lca[1000500][20];
int h[1000500];
int f(int a, int b) {
  for (int i = 19; i >= 0; i--) {
    if (h[lca[a][i]] >= h[b]) {
      a = lca[a][i];
    }
    if (h[lca[b][i]] >= h[a]) {
      b = lca[b][i];
    }
  }
  for (int i = 19; i >= 0; i--) {
    if (lca[a][i] != lca[b][i]) {
      a = lca[a][i];
      b = lca[b][i];
    }
  }
  return a == b ? a : lca[a][0];
}
int dist(int a, int b) {
  int c = f(a, b);
  return h[a] + h[b] - 2 * h[c];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n = 4;
  int q;
  cin >> q;
  lca[2][0] = 1;
  lca[3][0] = 1;
  lca[4][0] = 1;
  h[1] = 1;
  h[2] = h[3] = h[4] = 2;
  int curA = 2, curB = 3;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    lca[n + 1][0] = x;
    lca[n + 2][0] = x;
    h[n + 1] = h[n + 2] = h[x] + 1;
    for (int j = 1; j < 20; j++) {
      lca[n + 1][j] = lca[lca[n + 1][j - 1]][j - 1];
      lca[n + 2][j] = lca[lca[n + 2][j - 1]][j - 1];
    }
    vector<int> v = {curA, curB, n + 1, n + 2};
    int ans = -1, newA = 0, newB = 0;
    for (int a : v) {
      for (int b : v) {
        if (dist(a, b) > ans) {
          ans = dist(a, b);
          newA = a;
          newB = b;
        }
      }
    }
    curA = newA;
    curB = newB;
    cout << ans << "\n";
    n += 2;
  }
}
