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>
using namespace std;
long long get() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const long long N = 4e5 + 5;
long long n, m, col[N], ans[N], ins[N];
struct Edge {
  long long v, nxt;
} edge[N << 1];
long long head[N], tot;
vector<pair<long long, long long> > q[N];
long long c[N][2], f[N], s[N], si[N], s2i[N], lst[N];
void add(long long u, long long v) {
  edge[++tot] = (Edge){v, head[u]}, head[u] = tot;
}
void dfs(long long u, long long fa) {
  lst[u] = fa;
  for (long long i = head[u]; i; i = edge[i].nxt)
    if (edge[i].v != fa) dfs(edge[i].v, u);
}
long long chk(long long x) { return c[f[x]][1] == x; }
long long nroot(long long x) { return c[f[x]][chk(x)] == x; }
void pushup(long long x) { s[x] = s[c[x][0]] + s[c[x][1]] + si[x] + 1; }
void rotate(long long x) {
  long long y = f[x], z = f[y], k = chk(x), w = c[x][!k];
  if (nroot(y)) c[z][chk(y)] = x;
  c[x][!k] = y, c[y][k] = w;
  if (w) f[w] = y;
  f[y] = x, f[x] = z;
  pushup(y), pushup(x);
}
void splay(long long x) {
  while (nroot(x)) {
    long long y = f[x];
    if (nroot(y)) rotate(chk(x) ^ chk(y) ? x : y);
    rotate(x);
  }
}
void access(long long x) {
  for (long long y = 0; x; x = f[y = x]) {
    splay(x);
    si[x] += s[c[x][1]], s2i[x] += s[c[x][1]] * s[c[x][1]];
    c[x][1] = y, si[x] -= s[c[x][1]], s2i[x] -= s[c[x][1]] * s[c[x][1]];
  }
}
void link(long long x) {
  access(x), splay(x), access(lst[x]), splay(lst[x]),
      f[x] = lst[x], si[f[x]] += s[x], s2i[f[x]] += s[x] * s[x], pushup(f[x]);
}
void cut(long long x) {
  access(x), splay(x), c[x][0] = f[c[x][0]] = 0, pushup(x);
}
long long findroot(long long x) {
  access(x), splay(x);
  while (c[x][0]) x = c[x][0];
  splay(x);
  return x;
}
long long query(long long x) {
  long long rt = c[findroot(x)][1];
  return s[rt] * s[rt];
}
long long update(long long x) {
  long long res = 0;
  if (!ins[x]) {
    res = query(x);
    cut(x), res -= s2i[x] + s[c[x][1]] * s[c[x][1]];
    if (!ins[lst[x]]) res -= query(lst[x]);
  } else {
    res = s2i[x] + s[c[x][1]] * s[c[x][1]];
    if (!ins[lst[x]]) res += query(lst[x]);
    link(x), res -= query(x);
  }
  ins[x] ^= 1;
  return res;
}
signed main() {
  n = get(), m = get();
  for (long long i = 1; i <= n; i++)
    col[i] = get(), q[col[i]].push_back(make_pair(i, 0));
  for (long long i = 1, u, v; i < n; i++)
    u = get(), v = get(), add(u, v), add(v, u);
  dfs(1, n + 1);
  for (long long i = 1; i <= m; i++) {
    long long x = get(), y = get();
    q[col[x]].push_back(make_pair(x, i)),
        q[col[x] = y].push_back(make_pair(x, i));
  }
  for (long long i = 1; i <= n; i++) s[i] = 1;
  for (long long i = 1; i <= n; i++) link(i);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < q[i].size(); j++)
      ans[q[i][j].second] += update(q[i][j].first);
    for (long long j = 0; j < q[i].size(); j++) update(q[i][j].first);
  }
  for (long long i = 0; i <= m; i++)
    ans[i] += ans[i - 1], printf("%lld\n", ans[i]);
  return 0;
}