Problem: Nauuo is a girl who loves traveling.

One day she went to a tree, Old Driver Tree, literally, a tree with an old driver on it.

The tree is a connected graph consisting of n nodes and n-1 edges. Each node has a color, and Nauuo will visit the ODT through a simple path on the tree in the old driver's car.

Nauuo wants to visit see more different colors in her journey, but she doesn't know which simple path she will be traveling on. So, she wants to calculate the sum of the numbers of different colors on all different paths. Can you help her?

What's more, the ODT is being redecorated, so there will be m modifications, each modification will change a single node's color. Nauuo wants to know the answer after each modification too.

Note that in this problem, we consider the simple path from u to v and the simple path from v to u as two different simple paths if and only if u≠ v.

Input

The first line contains two integers n and m (2≤ n≤ 4⋅ 10^5, 1≤ m≤ 4⋅ 10^5) — the number of nodes and the number of modifications.

The second line contains n integers c_1,c_2,…,c_n (1≤ c_i≤ n), where c_i is the initial color of node i.

Each of the next n-1 lines contains two integers u and v (1≤ u,v≤ n), denoting there is an edge between u and v. It is guaranteed that the given edges form a tree.

Each of the next m lines contains two integers u and x (1≤ u,x≤ n), which means a modification that changes the color of node u into x.

Output

The output contains m+1 integers — the first integer is the answer at the beginning, the rest integers are the answers after every modification in the given order.

Examples

Input


5 3
1 2 1 2 3
1 2
1 3
3 4
3 5
3 3
4 1
4 3


Output


47
51
49
45


Input


6 1
1 1 1 1 1 1
1 2
2 3
3 4
4 5
5 6
1 2


Output


36
46

Note

Example 1

<image>

The number of colors on each simple path at the beginning:

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
long long fa[400010], ch[400010][2];
long long si[400010], size[400010], G[400010];
bool son(long long x) { return ch[fa[x]][1] == x; }
bool isroot(long long x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }
void pushup(long long x) {
  size[x] = size[ch[x][0]] + size[ch[x][1]] + si[x] + 1;
}
void Rotate(long long x) {
  if (!x || !fa[x] || isroot(x)) return;
  long long faz = fa[x], fazz = fa[faz], g = son(x);
  fa[x] = fazz;
  if (!isroot(faz)) ch[fazz][son(faz)] = x;
  fa[ch[x][!g]] = faz;
  ch[faz][g] = ch[x][!g];
  fa[faz] = x;
  ch[x][!g] = faz;
  pushup(faz);
  pushup(x);
}
void splay(long long node) {
  while (!isroot(node)) {
    if (!isroot(fa[node]))
      if (son(fa[node]) ^ son(node))
        Rotate(node);
      else
        Rotate(fa[node]);
    Rotate(node);
  }
  pushup(node);
}
void access(long long x) {
  for (long long y = 0; x; y = x, x = fa[x]) {
    splay(x);
    si[x] += size[ch[x][1]];
    si[x] -= size[y];
    G[x] += 1ll * size[ch[x][1]] * size[ch[x][1]];
    G[x] -= 1ll * size[y] * size[y];
    ch[x][1] = y;
    pushup(x);
  }
}
void link(long long x, long long y) {
  access(x);
  splay(x);
  access(y);
  splay(y);
  fa[x] = y;
  si[y] += size[x];
  G[y] += 1ll * size[x] * size[x];
  pushup(y);
}
long long find(long long x) {
  access(x);
  splay(x);
  while (ch[x][0]) x = ch[x][0];
  return x;
}
void cut(long long x, long long y) {
  access(x);
  splay(y);
  ch[y][1] = fa[x] = 0;
  pushup(y);
}
long long head[400010], nxt[800001], b[800001], k, n, m, c[400010], Fa[400010];
bool col[400010];
std::vector<std::pair<long long, long long> > que[400001];
void push(long long s, long long t) {
  nxt[++k] = head[s];
  head[s] = k;
  b[k] = t;
}
void dfs(long long x, long long f) {
  Fa[x] = fa[x] = f;
  size[x] = 1;
  for (long long i = head[x]; i; i = nxt[i])
    if (b[i] != f) {
      dfs(b[i], x);
      size[x] += size[b[i]];
      G[x] += 1ll * size[b[i]] * size[b[i]];
    }
  si[x] = size[x] - 1;
}
long long ans[400010];
long long f(long long x) {
  return 1ll * (size[ch[x][0]] + size[ch[x][1]]) *
             (size[ch[x][0]] + size[ch[x][1]]) +
         G[x];
}
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", c + i), que[c[i]].push_back(std::make_pair(0, i));
  for (long long i = 1, u, v; i < n; i++)
    scanf("%lld%lld", &u, &v), push(u, v), push(v, u);
  push(n + 1, 1);
  dfs(n + 1, 0);
  for (long long i = 1, u, col; i <= m; i++) {
    scanf("%lld%lld", &u, &col);
    if (c[u] == col) continue;
    que[col].push_back(std::make_pair(i, u));
    que[c[u]].push_back(std::make_pair(i, -u));
    c[u] = col;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < (long long)que[i].size(); j++) {
      long long t = que[i][j].first;
      if (que[i][j].second > 0) {
        long long u = que[i][j].second, v = Fa[u];
        col[u] ^= 1;
        access(u);
        splay(u);
        long long sz = size[u] - si[find(u)] - 1;
        splay(find(u));
        ans[t] += 1ll * sz * sz;
        cut(u, v);
        ans[t] -= f(u) + 1ll * (sz - size[u]) * (sz - size[u]);
      } else {
        long long u = -que[i][j].second, v = Fa[u];
        col[u] ^= 1;
        splay(u);
        long long tm = size[u];
        ans[t] += f(u);
        link(u, v);
        access(u);
        splay(u);
        long long sz = size[u] - si[find(u)] - 1;
        ans[t] -= 1ll * sz * sz - 1ll * (sz - tm) * (sz - tm);
        splay(find(u));
      }
    }
    for (long long j = 0; j < (long long)que[i].size(); j++) {
      long long u = que[i][j].second;
      if (u < 0) u = -u;
      if (col[u]) link(u, Fa[u]), col[u] = 0;
    }
  }
  for (long long i = 1; i <= m; i++) ans[i] += ans[i - 1];
  for (long long i = 0; i <= m; i++) printf("%lld\n", ans[i]);
}