#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
int n, q, a[MAXN], b[MAXN], d[MAXN], lazy[4 * MAXN], p[MAXN];
vector<int> g[MAXN], ord;
long long jump[MAXN][20];
pair<int, int> t[4 * MAXN];
map<pair<int, int>, int> ma;
void dfs(int v, int f = -1) {
  p[v] = f;
  if (f == 0) p[0] = 0;
  if (f == -1) d[v] = 0;
  ord.push_back(v);
  a[v] = ord.size() - 1;
  for (int u : g[v]) {
    if (u != f) {
      d[u] = d[v] + 1;
      dfs(u, v);
    }
  }
  b[v] = ord.size() - 1;
}
void init(int l, int r, int node = 1) {
  t[node] = pair<int, int>(r - l + 1, 0);
  if (l == r) return;
  int mid = (l + r) / 2;
  init(l, mid, 2 * node);
  init(mid + 1, r, 2 * node + 1);
}
void mark(int l, int r, int v, int node) {
  lazy[node] += v;
  t[node].second += v;
}
void prop(int l, int r, int node) {
  int mid = (l + r) / 2;
  mark(l, mid, lazy[node], 2 * node);
  mark(mid + 1, r, lazy[node], 2 * node + 1);
  lazy[node] = 0;
}
void upd(int u, int v, int w, int l = 0, int r = n - 1, int node = 1) {
  if (u == l && v == r) {
    mark(u, v, w, node);
    return;
  }
  prop(l, r, node);
  int mid = (l + r) / 2;
  if (v <= mid) {
    upd(u, v, w, l, mid, 2 * node);
  } else if (u >= mid + 1) {
    upd(u, v, w, mid + 1, r, 2 * node + 1);
  } else {
    upd(u, mid, w, l, mid, 2 * node);
    upd(mid + 1, v, w, mid + 1, r, 2 * node + 1);
  }
  if (t[2 * node].second < t[2 * node + 1].second) {
    t[node] = t[2 * node];
  }
  if (t[2 * node].second > t[2 * node + 1].second) t[node] = t[2 * node + 1];
  if (t[2 * node].second == t[2 * node + 1].second)
    t[node] = pair<int, int>(t[2 * node].first + t[2 * node + 1].first,
                             t[2 * node].second);
}
long long jup(long long a, long long x) {
  for (long long i = 19; i >= 0; --i) {
    if (x < (1 << i)) continue;
    a = jump[a][i];
    x -= (1 << i);
  }
  return a;
}
long long lca(long long a, long long b) {
  if (d[a] < d[b]) swap(a, b);
  long long x = d[a] - d[b];
  a = jup(a, x);
  assert(d[a] == d[b]);
  if (a == b) return a;
  for (long long i = 19; i >= 0; --i) {
    if (jump[a][i] == jump[b][i]) continue;
    a = jump[a][i];
    b = jump[b][i];
  }
  while (true) {
    if (a == b) return a;
    a = jump[a][0];
    b = jump[b][0];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0);
  for (long long i = 0; i < 20; ++i)
    for (long long j = 0; j < n; ++j) {
      if (i == 0)
        jump[j][i] = p[j];
      else
        jump[j][i] = jump[jump[j][i - 1]][i - 1];
    }
  init(0, n - 1, 1);
  for (int i = 0; i < q; ++i) {
    int u, v;
    cin >> u >> v;
    int c = 1;
    u--;
    v--;
    if (u > v) swap(u, v);
    if (ma[pair<int, int>(u, v)] == 0)
      c = 1;
    else
      c = -1;
    ma[pair<int, int>(u, v)] ^= 1;
    if (d[u] < d[v]) swap(u, v);
    int g = lca(u, v);
    if (v == g) {
      int y = jup(u, d[u] - d[v] - 1);
      upd(a[y], b[y], c);
      upd(a[u], b[u], -c);
    } else {
      upd(0, n - 1, c);
      upd(a[u], b[u], -c);
      upd(a[v], b[v], -c);
    }
    assert(t[1].second >= 0);
    if (t[1].second == 0)
      cout << t[1].first << "\n";
    else
      cout << 0 << "\n";
  }
}
