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 p1 = 1000000, p2 = 0;
char buf[1000005], wb[1000005];
int gc() {
  if (p1 >= 1000000) fread(buf, 1, 1000000, stdin), p1 = 0;
  return buf[p1++];
}
long long getint() {
  long long ret = 0, flag = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    ret = (ret << 3) + (ret << 1) + c - '0';
    c = getchar();
  }
  return ret * flag;
}
void pc(char x) {
  if (p2 >= 1000000) fwrite(wb, 1, 1000000, stdout), p2 = 0;
  wb[p2++] = x;
}
void wrt(long long x) {
  if (x < 0) pc('-'), x = -x;
  int c[24] = {0};
  if (!x) return pc('0'), void();
  while (x) c[++c[0]] = x % 10, x /= 10;
  while (c[0]) pc(c[c[0]--] + '0');
}
int n, m;
int c[400005], protoc[400005];
long long ans[400005], sum;
vector<int> pcc[400005];
vector<int> vec[400005];
struct que {
  int x, bc, ac;
} q[400005];
int prt[400005];
struct LCT {
  bool vt[400005];
  vector<int> act;
  struct node {
    int ch[2], fa, rev;
    int sum, suml;
    long long suml2;
  } v[400005];
  void init() {
    for (auto x : act)
      v[x].ch[0] = v[x].ch[1] = v[x].fa = v[x].rev = v[x].sum = v[x].suml =
          v[x].suml2 = 0;
    act.clear();
  }
  void push_up(int rt) {
    v[rt].sum = v[v[rt].ch[0]].sum + v[v[rt].ch[1]].sum + v[rt].suml + 1;
  }
  void push_down(int rt) {
    if (v[rt].rev) {
      swap(v[rt].ch[0], v[rt].ch[1]);
      v[v[rt].ch[0]].rev ^= 1, v[v[rt].ch[1]].rev ^= 1;
      v[rt].rev = 0;
    }
  }
  bool isroot(int x) { return v[v[x].fa].ch[0] != x && v[v[x].fa].ch[1] != x; }
  void pre_push_down(int x) {
    if (!isroot(x)) pre_push_down(v[x].fa);
    push_down(x);
  }
  void rot(int x) {
    int p = v[x].fa, g = v[p].fa;
    bool d = (v[p].ch[1] == x);
    if (!isroot(p)) v[g].ch[v[g].ch[1] == p] = x;
    v[p].ch[d] = v[x].ch[!d];
    v[v[x].ch[!d]].fa = p;
    v[x].ch[!d] = p;
    v[x].fa = g;
    v[p].fa = x;
    push_up(p);
    push_up(x);
  }
  void splay(int x) {
    pre_push_down(x);
    while (!isroot(x)) {
      int p = v[x].fa, g = v[p].fa;
      if (!isroot(p)) rot((v[p].ch[0] == x) ^ (v[g].ch[0] == p) ? x : p);
      rot(x);
    }
  }
  void access(int x) {
    for (int y = 0; x; y = x, x = v[x].fa) {
      splay(x);
      v[x].suml += v[v[x].ch[1]].sum;
      v[x].suml2 += 1ll * v[v[x].ch[1]].sum * v[v[x].ch[1]].sum;
      v[x].ch[1] = y;
      v[x].suml -= v[v[x].ch[1]].sum;
      v[x].suml2 -= 1ll * v[v[x].ch[1]].sum * v[v[x].ch[1]].sum;
      push_up(x);
    }
  }
  void makeroot(int x) {
    access(x), splay(x);
    v[x].rev ^= 1;
    push_up(x);
  }
  int find_root(int x) {
    access(x);
    splay(x);
    while (v[x].ch[0]) x = v[x].ch[0];
    return x;
  }
  void split(int x, int y) {
    makeroot(x);
    access(y);
    splay(y);
  }
  void link(int x, int y) {
    makeroot(x), makeroot(y);
    v[y].suml += v[x].sum, v[y].suml2 += 1ll * v[x].sum * v[x].sum, v[x].fa = y;
    push_up(y);
  }
  void cut(int x, int y) {
    split(x, y);
    if (v[y].ch[0] == x) v[y].ch[0] = 0, v[x].fa = 0;
  }
  void ins_val(int x) {
    x = find_root(x), splay(x), access(x);
    sum += v[x].suml2;
  }
  void del_val(int x) {
    x = find_root(x), splay(x), access(x);
    sum -= v[x].suml2;
  }
  int opration[800005];
  void Link(int x, bool flg = 1) {
    if (flg) opration[++opration[0]] = -x;
    del_val(x), del_val(prt[x]);
    access(x), splay(x);
    access(v[x].fa = prt[x]), splay(v[x].fa);
    v[v[x].fa].suml += v[x].sum, v[v[x].fa].suml2 += 1ll * v[x].sum * v[x].sum;
    if (!vt[x]) vt[x] = 1, act.push_back(x);
    if (!vt[v[x].fa]) vt[v[x].fa] = 1, act.push_back(v[x].fa);
    ins_val(x);
  }
  void Cut(int x, bool flg = 1) {
    if (flg) opration[++opration[0]] = x;
    int p = 0;
    del_val(x);
    access(x), splay(x);
    v[x].ch[0] = v[p = v[x].ch[0]].fa = 0;
    push_up(x), ins_val(x), ins_val(p);
  }
  void reback() {
    while (opration[0]) {
      if (opration[opration[0]] > 0) Link(opration[opration[0]--], 0);
      if (opration[opration[0]] < 0) Cut(-opration[opration[0]--], 0);
    }
  }
} T;
struct edge {
  int ne, v;
} e[800005];
int cnt, head[400005];
void add(int u, int v) {
  ++cnt;
  e[cnt].v = v;
  e[cnt].ne = head[u];
  head[u] = cnt;
}
void dfs(int x) {
  for (int i = head[x]; i; i = e[i].ne) {
    int y = e[i].v;
    if (y == prt[x]) continue;
    prt[y] = x, dfs(y), T.Link(y);
  }
}
void solve(int c) {
  for (auto i : pcc[c]) T.Cut(i);
  ans[0] += sum, sum = 0;
  for (auto i : vec[c]) {
    if (q[i].ac == q[i].bc) continue;
    if (q[i].ac == c) T.Cut(q[i].x);
    if (q[i].bc == c) T.Link(q[i].x);
    ans[i] += sum, sum = 0;
  }
  T.reback(), sum = 0;
}
int main() {
  n = getint();
  m = getint();
  for (int i = 1; i <= n; i++)
    protoc[i] = c[i] = getint(), pcc[c[i]].push_back(i);
  for (int i = 1; i < n; i++) {
    int u = getint(), v = getint();
    add(u, v), add(v, u);
  }
  dfs(1), prt[1] = n + 1, T.Link(1), sum = 0, T.opration[0] = 0;
  for (int i = 1; i <= m; i++) {
    q[i].x = getint();
    q[i].bc = c[q[i].x];
    c[q[i].x] = q[i].ac = getint();
    vec[q[i].bc].push_back(i);
    vec[q[i].ac].push_back(i);
  }
  for (int i = 1; i <= n; i++) solve(i);
  for (int i = 1; i <= m; i++) ans[i] += ans[i - 1];
  for (int i = 0; i <= m; i++) wrt(-ans[i]), pc('\n');
  fwrite(wb, 1, p2, stdout);
  return 0;
}