#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e6 + 10;
template <typename T>
struct rmq {
  vector<T> v;
  int n;
  static const int b = 32;
  vector<int> mask, t;
  int op(int x, int y) { return v[x] < v[y] ? x : y; }
  int msb(int x) {
    { return __builtin_clz(0) - __builtin_clz(x) - 1; }
  }
  rmq() {}
  rmq(const vector<T> &v_) : v(v_), n(v.size()), mask(n), t(n) {
    for (int i = 0, at = 0; i < v.size(); mask[i++] = at |= 1) {
      at = (at << 1) & ((1 << b) - 1);
      while (at and op(i, i - msb(at & -at)) == i) at ^= at & -at;
    }
    for (int i = 0; i < n / b; i++)
      t[i] = b * i + b - 1 - msb(mask[b * i + b - 1]);
    for (int j = 1; (1 << j) <= n / b; j++)
      for (int i = 0; i + (1 << j) <= n / b; i++)
        t[n / b * j + i] =
            op(t[n / b * (j - 1) + i], t[n / b * (j - 1) + i + (1 << (j - 1))]);
  }
  int small(int r, int sz = b) { return r - msb(mask[r] & ((1 << sz) - 1)); }
  T query(int l, int r) {
    if (r - l + 1 <= b) return small(r, r - l + 1);
    int ans = op(small(l + b - 1), small(r));
    int x = l / b + 1, y = r / b - 1;
    if (x <= y) {
      int j = msb(y - x + 1);
      ans = op(ans, op(t[n / b * j + x], t[n / b * j + y - (1 << j) + 1]));
    }
    return ans;
  }
};
namespace lca {
vector<int> g[MAX];
int v[2 * MAX], pos[MAX], dep[2 * MAX];
int t;
rmq<int> RMQ;
void dfs(int i, int d = 0, int p = -1) {
  v[t] = i, pos[i] = t, dep[t++] = d;
  for (int j : g[i])
    if (j != p) {
      dfs(j, d + 1, i);
      v[t] = i, dep[t++] = d;
    }
}
void build(int n, int root) {
  t = 0;
  dfs(root);
  RMQ = rmq<int>(vector<int>(v, v + 2 * n));
}
int lca(int a, int b) {
  a = pos[a], b = pos[b];
  return v[RMQ.query(min(a, b), max(a, b))];
}
int dist(int a, int b) {
  return dep[pos[a]] + dep[pos[b]] - 2 * dep[pos[lca(a, b)]];
}
}  // namespace lca
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  lca::g[1].push_back(2);
  lca::g[1].push_back(3);
  lca::g[1].push_back(4);
  int n = 4;
  int q;
  cin >> q;
  vector<pair<int, int> > query(q);
  for (pair<int, int> &e : query) {
    int a = ++n, b = ++n;
    e = {a, b};
    int c;
    cin >> c;
    lca::g[c].push_back(a);
    lca::g[c].push_back(b);
  }
  lca::build(n, 1);
  int l = 2, r = 3, dim = 2;
  for (pair<int, int> &e : query) {
    int a, b;
    tie(a, b) = e;
    int dla = lca::dist(l, a);
    int dra = lca::dist(r, a);
    dim = max({dim, dla, dra});
    if (dim == dla)
      r = a;
    else if (dim == dra)
      l = a;
    cout << dim << '\n';
  }
  exit(0);
}
