#include <bits/stdc++.h>
using namespace std;
struct Tree {
  int n;
  vector<vector<int>> g;
  vector<int> sz, pa, depth, sta, fin, tour;
  int tim;
  Tree(int _n) : n(_n), g(n), sz(n), pa(n, -1), depth(n), sta(n), fin(n) {
    tour.reserve(n);
    input();
    tim = 0;
    basic_dfs(0);
    build_lca();
  }
  int L;
  vector<vector<int>> pa_up;
  void build_lca() {
    L = 0;
    while ((1 << L) < n - 1) L++;
    pa_up = vector<vector<int>>(L + 1, vector<int>(n));
    pa[0] = 0;
    for (int u : tour) {
      pa_up[0][u] = pa[u];
      for (int j = 1; j <= L; j++) {
        pa_up[j][u] = pa_up[j - 1][pa_up[j - 1][u]];
      }
    }
  }
  inline void add(int u, int v) { g[u].emplace_back(v); }
  void input() {
    for (int v : {1, 2, 3}) add(0, v);
    for (int _ = 4, v = 4; _ < n; _ += 2) {
      int x;
      cin >> x;
      x--;
      add(x, v++);
      add(x, v++);
    }
  }
  void basic_dfs(int u) {
    sta[u] = tim++;
    tour.emplace_back(u);
    for (int& v : g[u]) {
      pa[v] = u;
      depth[v] = depth[u] + 1;
      basic_dfs(v);
      sz[u] += sz[v];
    }
    ++sz[u];
    fin[u] = tim;
  }
  inline bool is_ancestor(int u, int v) {
    return sta[u] <= sta[v] && fin[v] <= fin[u];
  }
  inline int lca(int u, int v) {
    if (is_ancestor(u, v)) return u;
    if (is_ancestor(v, u)) return v;
    for (int j = L; j >= 0; j--) {
      if (!is_ancestor(pa_up[j][u], v)) u = pa_up[j][u];
    }
    return pa_up[0][u];
  }
  int dist(int u, int v) { return depth[u] + depth[v] - 2 * depth[lca(u, v)]; }
  int goup(int u, int step) {
    for (int j = L; j >= 0; j--) {
      if (step >> j & 1) u = pa_up[j][u];
    }
    return u;
  }
  void solve() {
    int x = 1, y = 2;
    int len = 2;
    for (int k = 4; k < n; k += 2) {
      for (int z : {k, k + 1}) {
        if (dist(x, z) > len) y = z;
        if (dist(y, z) > len) x = z;
      }
      len = dist(x, y);
      cout << len << '\n';
    }
  }
};
void solve() {
  int q;
  cin >> q;
  Tree tr(4 + 2 * q);
  tr.solve();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
