#include <bits/stdc++.h>
using namespace std;
const int mv = int(5e5) * 2 + 10, me = 2 * mv, mlog = 20;
const int inf = int(1e7);
int ant[me], to[me], prox[me], adj[mv], z;
int size[mv], maxDown[mv], go[mv];
int rk[mv];
inline void add(int a, int b) {
  ant[z] = adj[a], to[z] = b, adj[a] = z;
  prox[ant[z]] = z, prox[z] = -1;
  ++z;
  swap(a, b);
  ant[z] = adj[a], to[z] = b, adj[a] = z;
  prox[ant[z]] = z, prox[z] = -1;
  ++z;
}
inline void del(int i) {
  if (prox[i] == -1)
    adj[to[i ^ 1]] = ant[i];
  else
    ant[prox[i]] = ant[i];
  if (ant[i] != -1) prox[ant[i]] = prox[i];
}
void dfs(int u, int p) {
  size[u] = 1;
  maxDown[u] = 0;
  go[u] = u;
  for (int i = adj[u]; i > -1; i = ant[i]) {
    if (to[i] == p) continue;
    dfs(to[i], u);
    size[u] += size[to[i]];
    if (size[to[i]] > maxDown[u]) {
      maxDown[u] = size[to[i]];
      go[u] = to[i];
    }
  }
}
int getCentroid(int u) {
  dfs(u, u);
  int sz = size[u] / 2;
  while (maxDown[u] > sz) {
    u = go[u];
  }
  return u;
}
int par[mv], dist[mv][mlog];
void setDist(int u, int p, int level, int d) {
  dist[u][level] = d;
  for (int i = adj[u]; i > -1; i = ant[i]) {
    if (to[i] == p) continue;
    setDist(to[i], u, level, d + 1);
  }
}
void init(int u, int p = -1, int level = 1) {
  u = getCentroid(u);
  par[u] = p;
  rk[u] = level;
  for (int i = adj[u]; i > -1; i = ant[i]) {
    del(i);
    del(i ^ 1);
    setDist(to[i], u, level, 1);
    init(to[i], u, level + 1);
  }
}
pair<int, int> save[mv][3];
int getAns(int u, int ls, int at) {
  if (at < 0) return -inf;
  int d = dist[u][rk[at]], dto = 0;
  if (save[at][0].second == ls) {
    dto = save[at][1].first;
  } else {
    dto = save[at][0].first;
  }
  int sum = d + dto;
  if (at > u) {
    sum = 0;
  }
  return max(sum, getAns(u, at, par[at]));
}
void ins(int u, int ls, int at) {
  if (at < 0) return;
  int d = dist[u][rk[at]];
  if (save[at][0].second == ls) {
    save[at][0].first = max(d, save[at][0].first);
  } else if (save[at][1].second == ls) {
    save[at][1].first = max(d, save[at][1].first);
    sort(save[at], save[at] + 2, greater<pair<int, int> >());
  } else {
    save[at][2] = pair<int, int>(d, ls);
    sort(save[at], save[at] + 3, greater<pair<int, int> >());
  }
  ins(u, at, par[at]);
}
int ans[mv];
int main() {
  memset(adj, -1, sizeof adj);
  int n = 4;
  for (int i = 1, __ = n; i < __; ++i) add(0, i);
  int q;
  cin >> q;
  for (int i = 0, __ = q; i < __; ++i) {
    int v;
    scanf("%d", &v);
    v--;
    add(v, n++);
    add(v, n++);
  }
  for (int i = 0, __ = n; i < __; ++i) {
    save[i][0] = pair<int, int>(0, i);
    save[i][1] = pair<int, int>(0, i);
  }
  init(0);
  for (int i = 0, __ = n; i < __; ++i) {
    int id = max((i - 4) / 2, 0);
    if (id) {
      ans[id] = max(ans[id], ans[id - 1]);
    }
    int ma = getAns(i, i, i);
    ans[id] = max(ans[id], ma);
    ins(i, i, i);
  }
  for (int i = 0, __ = q; i < __; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
