#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1000 * 1000 + 10;
const int Maxl = 25;
int dis[Maxn];
int par[Maxn][Maxl];
int n = 4, q;
int getpar(int x, int num) {
  for (int i = 19; i >= 0; i--)
    if ((1 << i) & num) x = par[x][i];
  return x;
}
int LCA(int x, int y) {
  if (dis[x] < dis[y]) swap(x, y);
  x = getpar(x, dis[x] - dis[y]);
  if (x == y) return x;
  for (int i = 19; i >= 0; i--)
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  return par[x][0];
}
int d(int x, int y) {
  int j = LCA(x, y);
  return (dis[x] + dis[y] - 2 * dis[j]);
}
int main() {
  cin >> q;
  dis[1] = 0;
  dis[2] = dis[3] = dis[4] = 1;
  memset(par, -1, sizeof(par));
  par[1][0] = par[2][0] = par[3][0] = par[4][0] = 1;
  int head = 2, tail = 3;
  int diam = 2;
  int hp, tp;
  for (int i = 0, v; i < q; i++) {
    scanf("%d", &v);
    dis[n + 1] = dis[v] + 1;
    dis[n + 2] = dis[v] + 1;
    par[n + 1][0] = v;
    par[n + 2][0] = v;
    for (int i = 1; i < Maxl && par[par[n + 1][i - 1]][i - 1] != -1; i++) {
      par[n + 1][i] = par[par[n + 1][i - 1]][i - 1];
      par[n + 2][i] = par[par[n + 2][i - 1]][i - 1];
    }
    int di = d(n + 1, head);
    if (di >= diam) {
      tp = n + 1;
      hp = head;
      diam = di;
    }
    di = d(n + 2, head);
    if (di >= diam) {
      tp = n + 2;
      hp = head;
      diam = di;
    }
    di = d(n + 1, tail);
    if (di >= diam) {
      tp = n + 1;
      hp = tail;
      diam = di;
    }
    di = d(n + 2, tail);
    if (di >= diam) {
      tp = n + 2;
      hp = tail;
      diam = di;
    }
    head = hp;
    tail = tp;
    n += 2;
    printf("%d \n", diam);
  }
  return 0;
}
