#include <bits/stdc++.h>
const int M = 1000005;
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0, w = 1;
  while (c > '9' || c < '0') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * w;
}
int n, m, hea[M], num, q[M], dep[M], st[M][20];
int l[M], r[M], to[M], f[M], Res[M];
struct E {
  int Nxt, to;
} edge[M << 1];
inline void add_edge(int from, int to) {
  edge[++num].Nxt = hea[from];
  edge[num].to = to;
  hea[from] = num;
}
int find(int x) {
  if (f[x] != x) f[x] = find(f[x]);
  return f[x];
}
void Dfs(int u, int father, int depth) {
  dep[u] = depth;
  st[u][0] = father;
  for (int i = hea[u], v; i; i = edge[i].Nxt) {
    v = edge[i].to;
    if (v == father) continue;
    Dfs(v, u, depth + 1);
  }
}
inline void ST() {
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i <= n; i++) st[i][j] = st[st[i][j - 1]][j - 1];
}
inline int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (dep[st[u][i]] >= dep[v]) u = st[u][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (st[u][i] != st[v][i]) u = st[u][i], v = st[v][i];
  return st[u][0];
}
int u, v, Ans, el, er, d;
inline void Solve(int x, int y) {
  u = find(x), v = find(y);
  Ans = 0, el = 0, er = 0, d = 0;
  Ans = dep[l[u]] + dep[r[u]] - (dep[LCA(l[u], r[u])] << 1), el = l[u],
  er = r[u];
  d = dep[l[v]] + dep[r[v]] - (dep[LCA(l[v], r[v])] << 1);
  if (d > Ans) Ans = d, el = l[v], er = r[v];
  d = dep[l[u]] + dep[l[v]] - (dep[LCA(l[u], l[v])] << 1);
  if (d > Ans) Ans = d, el = l[u], er = l[v];
  d = dep[l[u]] + dep[r[v]] - (dep[LCA(l[u], r[v])] << 1);
  if (d > Ans) Ans = d, el = l[u], er = r[v];
  d = dep[l[v]] + dep[r[u]] - (dep[LCA(l[v], r[u])] << 1);
  if (d > Ans) Ans = d, el = l[v], er = r[u];
  d = dep[r[u]] + dep[r[v]] - (dep[LCA(r[u], r[v])] << 1);
  f[v] = u;
  l[u] = el, r[u] = er;
}
int main() {
  m = read();
  n = 1;
  q[1] = 1;
  q[2] = 1;
  to[1] = ++n;
  add_edge(1, to[1]);
  add_edge(to[1], 1);
  to[2] = ++n;
  add_edge(1, to[2]);
  add_edge(to[2], 1);
  to[3] = ++n;
  add_edge(1, to[3]);
  add_edge(to[3], 1);
  for (int i = 3; i <= m + 2; i++) {
    q[i] = read();
    to[i * 2 - 1] = ++n;
    add_edge(q[i], to[i * 2 - 1]);
    add_edge(to[i * 2 - 1], q[i]);
    to[i << 1] = ++n;
    add_edge(q[i], to[i << 1]);
    add_edge(to[i << 1], q[i]);
  }
  for (int i = 1; i <= n; i++) f[i] = i, l[i] = i, r[i] = i;
  Dfs(1, 1, 1);
  ST();
  for (int i = 1; i <= m + 3; i++) {
    Solve(q[i], to[i * 2 - 1]);
    if (i == 2) continue;
    Solve(q[i], to[i << 1]);
    if (i > 2) {
      int u = find(q[i]);
      Res[i - 2] = dep[l[u]] + dep[r[u]] - (dep[LCA(l[u], r[u])] << 1);
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", Res[i]);
  return 0;
}
