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;
const int maxn = 400000 + 10;
const int maxt = maxn;
struct tnode {
  int f, c[2], rev;
  long long v1, v2, xv1, xv2;
  tnode() {}
  tnode(int val) {
    f = c[0] = c[1] = rev = 0;
    xv1 = xv2 = v1 = v2 = 0;
  }
} t[maxt];
inline int isroot(int u) {
  int f = t[u].f;
  return t[f].c[0] != u && t[f].c[1] != u;
}
long long sqr(long long x) { return 1LL * x * x; }
inline void pushup(int u) {
  int ls = t[u].c[0], rs = t[u].c[1];
  t[u].v1 = t[ls].v1 + t[rs].v1 + 1 + t[u].xv1;
  t[u].v2 = t[u].xv2 + sqr(t[ls].v1) + sqr(t[rs].v1);
}
inline void rot(int x) {
  int y = t[x].f, z = t[y].f;
  int l = t[y].c[1] == x;
  if (!isroot(y)) t[z].c[t[z].c[1] == y] = x;
  t[y].c[l] = t[x].c[l ^ 1];
  t[x].c[l ^ 1] = y;
  t[x].f = z;
  t[y].f = x;
  if (t[y].c[l]) t[t[y].c[l]].f = y;
  pushup(y);
  pushup(x);
}
inline void splay(int x) {
  while (!isroot(x)) {
    int y = t[x].f, z = t[y].f;
    if (!isroot(y)) {
      if ((t[z].c[1] == y) ^ (t[y].c[1] == x))
        rot(x);
      else
        rot(y);
    }
    rot(x);
  }
}
inline void access(int u) {
  for (int i = 0; u; i = u, u = t[u].f) {
    splay(u);
    if (t[u].c[1])
      t[u].xv1 += t[t[u].c[1]].v1, t[u].xv2 += sqr(t[t[u].c[1]].v1);
    t[u].c[1] = i;
    if (i) t[u].xv1 -= t[i].v1, t[u].xv2 -= sqr(t[i].v1);
    pushup(u);
  }
}
int n, m, col[maxn], h[maxn], ecnt;
struct enode {
  int v, n;
  enode() {}
  enode(int _v, int _n) : v(_v), n(_n) {}
} e[maxn << 1];
inline void addedge(int u, int v) {
  ecnt++;
  e[ecnt] = enode(v, h[u]);
  h[u] = ecnt;
}
int pre[maxn];
void dfs(int u, int fa) {
  pre[u] = fa;
  for (int i = h[u]; ~i; i = e[i].n) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, u);
  }
}
struct qnode {
  int u, t, kd;
  qnode() {}
  qnode(int _u, int _t, int _kd) : u(_u), t(_t), kd(_kd){};
};
vector<qnode> q[maxn];
long long Ans[maxn];
int id;
inline int findfa(int u) {
  access(u);
  splay(u);
  while (t[u].c[0]) u = t[u].c[0];
  return u;
}
inline void link(int u) {
  int f = findfa(pre[u]);
  splay(f);
  splay(u);
  Ans[id] += t[f].v2;
  Ans[id] += t[u].v2;
  int p = pre[u];
  access(p);
  splay(p);
  splay(u);
  t[u].f = p;
  t[p].xv1 += t[u].v1;
  t[p].xv2 += sqr(t[u].v1);
  pushup(p);
  splay(f);
  Ans[id] -= t[f].v2;
}
inline void cut(int u) {
  int p = pre[u], f = findfa(p);
  splay(f);
  Ans[id] += t[f].v2;
  access(p);
  splay(p);
  splay(u);
  t[u].f = 0;
  t[p].xv1 -= t[u].v1;
  t[p].xv2 -= sqr(t[u].v1);
  pushup(p);
  splay(f);
  splay(u);
  Ans[id] -= t[f].v2;
  Ans[id] -= t[u].v2;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(h, -1, sizeof(h));
  ecnt = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &col[i]), q[col[i]].push_back(qnode(i, 0, 0));
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  dfs(1, n + 1);
  for (int i = 1; i <= m; i++) {
    int u, c;
    scanf("%d%d", &u, &c);
    q[col[u]].push_back(qnode(u, i, 1));
    col[u] = c;
    q[c].push_back(qnode(u, i, 0));
  }
  for (int i = 1; i <= n; i++) q[col[i]].push_back(qnode(i, m + 1, 1));
  id = 0;
  for (int i = 1; i <= n; i++) {
    t[i] = tnode(0);
    pushup(i);
  }
  for (int i = 1; i <= n; i++) link(i);
  Ans[0] = 0;
  for (int i = 1; i <= n; i++) {
    int Sz = q[i].size();
    if (!Sz) {
      continue;
    }
    for (int j = 0; j < Sz; j++) {
      qnode now = q[i][j];
      id = now.t;
      if (now.kd)
        link(now.u);
      else
        cut(now.u);
    }
  }
  for (int i = 1; i <= m; i++) Ans[i] += Ans[i - 1];
  for (int i = 0; i <= m; i++) printf("%I64d\n", Ans[i]);
  return 0;
}