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;
int rdn() {
  int ret = 0;
  bool fx = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') fx = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
  return fx ? ret : -ret;
}
long long Sqr(int x) { return (long long)x * x; }
const int N = 1e6 + 5, M = N * 3;
int n, m, col[N], hd[N], xnt, to[M], nxt[M];
int f[N], fa[N], c[N][2], siz[N], sizi[N];
int p[N], tot;
bool vis[N];
long long siz2i[N], tmp, dlt[N];
bool isrt(int x) { return c[fa[x]][0] != x && c[fa[x]][1] != x; }
void pshp(int x) { siz[x] = siz[c[x][0]] + siz[c[x][1]] + sizi[x] + 1; }
void rotate(int x) {
  int y = fa[x], z = fa[y];
  bool d = (x == c[y][1]);
  if (!isrt(y)) c[z][y == c[z][1]] = x;
  fa[x] = z;
  fa[y] = x;
  fa[c[x][!d]] = y;
  c[y][d] = c[x][!d];
  c[x][!d] = y;
  pshp(y);
  pshp(x);
}
void splay(int x) {
  for (int y, z; !isrt(x); rotate(x)) {
    y = fa[x];
    z = fa[y];
    if (!isrt(y)) ((y == c[z][0]) ^ (x == c[y][0])) ? rotate(x) : rotate(y);
  }
}
void access(int x) {
  for (int t = 0; x; t = x, x = fa[x]) {
    splay(x);
    int y = c[x][1];
    sizi[x] += siz[y];
    siz2i[x] += Sqr(siz[y]);
    sizi[x] -= siz[t];
    siz2i[x] -= Sqr(siz[t]);
    c[x][1] = t;
    pshp(x);
  }
}
int fnd_rt(int x) {
  access(x);
  splay(x);
  while (c[x][0]) x = c[x][0];
  splay(x);
  return x;
}
void link(int x) {
  splay(x);
  tmp -= Sqr(siz[c[x][1]]) + siz2i[x];
  int y = f[x], rt = fnd_rt(y);
  splay(rt);
  tmp -= Sqr(siz[c[rt][1]]);
  splay(y);
  fa[x] = y;
  sizi[y] += siz[x];
  siz2i[y] += Sqr(siz[x]);
  pshp(y);
  access(x);
  splay(rt);
  tmp += Sqr(siz[c[rt][1]]);
}
void cut(int x) {
  int rt = fnd_rt(x);
  tmp += siz2i[x];
  tmp -= Sqr(siz[c[rt][1]]);
  int y = f[x];
  splay(y);
  c[y][1] = 0;
  fa[x] = 0;
  pshp(y);
  splay(rt);
  tmp += Sqr(siz[c[rt][1]]);
}
namespace Q {
int hd[N], xnt, to[M], id[M], nxt[M];
void add(int x, int y, int i) {
  to[++xnt] = y;
  nxt[xnt] = hd[x];
  hd[x] = xnt;
  id[xnt] = i;
}
void solve(int cr) {
  tot = 0;
  for (int i = hd[cr]; i; i = nxt[i]) p[++tot] = i;
  for (int i = tot, d; i; i--) {
    tmp = 0;
    d = p[i];
    if (vis[to[d]])
      link(to[d]);
    else
      cut(to[d]);
    dlt[id[d]] += tmp;
    vis[to[d]] ^= 1;
  }
}
void solve2(int cr) {
  for (int i = hd[cr]; i; i = nxt[i]) {
    tmp = 0;
    if (vis[to[i]])
      link(to[i]);
    else
      cut(to[i]);
    vis[to[i]] ^= 1;
  }
}
}  // namespace Q
namespace I {
int hd[N], xnt, to[N], nxt[N];
void add(int x, int y) {
  to[++xnt] = y;
  nxt[xnt] = hd[x];
  hd[x] = xnt;
}
void solve(int cr) {
  tot = 0;
  for (int i = hd[cr]; i; i = nxt[i]) p[++tot] = to[i];
  tmp = 0;
  for (int i = tot; i; i--) {
    if (vis[p[i]])
      link(p[i]);
    else
      cut(p[i]);
    vis[p[i]] ^= 1;
  }
  dlt[0] += tmp;
}
void solve2(int cr) {
  for (int i = hd[cr]; i; i = nxt[i]) {
    tmp = 0;
    if (vis[to[i]])
      link(to[i]);
    else
      cut(to[i]);
    vis[to[i]] ^= 1;
  }
}
}  // namespace I
void add(int x, int y) {
  to[++xnt] = y;
  nxt[xnt] = hd[x];
  hd[x] = xnt;
}
void ini_dfs(int cr, int fa) {
  f[cr] = fa;
  for (int i = hd[cr], v; i; i = nxt[i])
    if ((v = to[i]) != fa) ini_dfs(v, cr);
}
int main() {
  n = rdn();
  m = rdn();
  for (int i = 2; i <= n + 1; i++) {
    col[i] = rdn();
    I::add(col[i], i);
  }
  for (int i = 1, u, v; i < n; i++)
    u = rdn() + 1, v = rdn() + 1, add(u, v), add(v, u);
  add(1, 2);
  add(2, 1);
  ini_dfs(1, 0);
  for (int i = 1, u, d; i <= m; i++) {
    u = rdn() + 1;
    d = rdn();
    Q::add(col[u], u, i);
    col[u] = d;
    Q::add(d, u, i);
  }
  for (int i = 2; i <= n + 1; i++) siz[i] = 1;
  for (int i = 2; i <= n + 1; i++) link(i);
  dlt[0] = (long long)n * n * n;
  for (int i = 1; i <= n; i++) {
    I::solve(i);
    Q::solve(i);
    Q::solve2(i);
    I::solve2(i);
  }
  long long ans = (long long)n * n * n;
  for (int i = 0; i <= m; i++) {
    ans -= dlt[i];
    printf("%lld\n", ans);
  }
  return 0;
}