#include <bits/stdc++.h>
using namespace std;
const int mx = 1e6 + 10;
static int lca[mx][20], l[mx];
int a, b, q, n, v, dm;
int calc_lca(int x, int y) {
  if (l[x] < l[y]) swap(x, y);
  while (l[x] > l[y]) {
    int tmp = log2(l[x] - l[y]);
    x = lca[x][tmp];
  }
  int j = log2(l[x]);
  while (x != y) {
    while (lca[x][j] == lca[y][j] && j > 0) j--;
    x = lca[x][j], y = lca[y][j];
  }
  return x;
}
void add_node() {
  ++n;
  l[n] = l[v] + 1;
  lca[n][0] = v;
  int j = 1, p = v;
  while (p > -1) {
    p = lca[p][j - 1];
    lca[n][j++] = p;
  }
}
void preprocess() {
  memset(lca, -1, sizeof lca);
  l[1] = 0;
  l[2] = l[3] = l[4] = 1;
  n = 4;
  dm = 2;
  lca[2][0] = lca[3][0] = lca[4][0] = 1;
  a = 2, b = 3;
}
int main() {
  ios::sync_with_stdio(0);
  preprocess();
  cin >> q;
  while (q--) {
    cin >> v;
    add_node();
    add_node();
    int l1 = calc_lca(a, n), l2 = calc_lca(b, n);
    if (l[a] - l[l1] + l[n] - l[l1] > dm)
      b = n, dm = l[a] - l[l1] + l[n] - l[l1];
    else if (l[b] - l[l2] + l[n] - l[l2] > dm)
      a = n, dm = l[b] - l[l2] + l[n] - l[l2];
    cout << dm << '\n';
  }
  return 0;
}
