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>
inline int read() {
  char c, _c;
  int x;
  for (c = _c = getchar(); !isdigit(c); c = getchar()) {
    _c = c;
  }
  for (x = 0; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  return _c == '-' ? -x : x;
}
const int N = 1e6 + 5;
int n, q, ft[N], col[N];
long long ans[N];
std::vector<std::pair<int, int>> mdf[N];
struct List {
  int tot, fst[N], nxt[N], to[N];
  List() { memset(fst, -1, sizeof(fst)); }
  inline void insert(int u, int v) {
    nxt[tot] = fst[u];
    to[tot] = v;
    fst[u] = tot++;
  }
  inline void link(int u, int v) {
    insert(u, v);
    insert(v, u);
  }
} e;
struct LinkCutTree {
  int ft[N], son[N][2], siz[N], ss[N];
  long long sf[N];
  inline bool isRight(int u) { return son[ft[u]][0] != u; }
  inline bool isRoot(int u) { return son[ft[u]][0] != u && son[ft[u]][1] != u; }
  inline void connect(int u, int fa, int d) {
    ft[u] = fa;
    son[fa][d] = u;
  }
  inline void pushUp(int u) {
    siz[u] = siz[son[u][0]] + siz[son[u][1]] + ss[u] + 1;
  }
  inline void rotate(int u) {
    int fa = ft[u], ud = isRight(u), v = son[u][ud ^ 1];
    int ga = ft[fa], fd = isRight(fa);
    ft[u] = ga;
    if (!isRoot(fa)) {
      son[ga][fd] = u;
    }
    connect(v, fa, ud);
    connect(fa, u, ud ^ 1);
    pushUp(fa);
  }
  void splay(int u) {
    for (int fa = ft[u]; !isRoot(u); rotate(u), fa = ft[u]) {
      if (!isRoot(fa)) {
        rotate(isRight(u) == isRight(fa) ? fa : u);
      }
    }
    pushUp(u);
  }
  void access(int u) {
    for (int v = 0; u > 0; v = u, u = ft[u]) {
      splay(u);
      ss[u] += siz[son[u][1]] - siz[v];
      sf[u] += 1ll * siz[son[u][1]] * siz[son[u][1]] - 1ll * siz[v] * siz[v];
      son[u][1] = v;
      pushUp(u);
    }
  }
  int findRoot(int u) {
    access(u);
    splay(u);
    for (; son[u][0] > 0; u = son[u][0])
      ;
    return u;
  }
  void link(int u, int v) {
    access(u);
    splay(u);
    access(v);
    splay(v);
    connect(u, v, 1);
    pushUp(v);
  }
  void cut(int u) {
    access(u);
    splay(u);
    int v = son[u][0];
    ft[v] = son[u][0] = 0;
    pushUp(u);
  }
  long long query(int u) {
    u = findRoot(u);
    splay(u);
    u = son[u][1];
    return 1ll * siz[u] * siz[u];
  }
  long long querys(int u) {
    u = findRoot(u);
    splay(u);
    return 1ll * siz[son[u][0]] * siz[son[u][0]] +
           1ll * siz[son[u][1]] * siz[son[u][1]] + sf[u];
  }
} lct;
void dfs(int u, int fa) {
  ft[u] = fa;
  if (fa > 0) {
    lct.link(u, fa);
  }
  for (int i = e.fst[u]; ~i; i = e.nxt[i]) {
    int v = e.to[i];
    if (v != fa) {
      dfs(v, u);
    }
  }
}
int main() {
  n = read();
  q = read();
  for (int u = 1; u <= n; u++) {
    col[u] = read();
    mdf[col[u]].push_back({u, 0});
  }
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    e.link(u, v);
  }
  e.link(n + 1, 1);
  dfs(n + 1, 0);
  for (int i = 1; i <= q; i++) {
    int u = read();
    mdf[col[u]].push_back({u, i});
    col[u] = read();
    mdf[col[u]].push_back({u, i});
  }
  for (int u = 1; u <= n; u++) {
    col[u] = 0;
  }
  for (int x = 1; x <= n; x++) {
    for (int i = 0; i < (int)mdf[x].size(); i++) {
      int u = mdf[x][i].first, j = mdf[x][i].second, fa = ft[u];
      col[u] ^= 1;
      if (col[u] == 1) {
        ans[j] += lct.query(u);
        lct.cut(u);
        ans[j] -= lct.querys(u);
        if (col[fa] == 0) {
          ans[j] -= lct.query(fa);
        }
      } else {
        if (col[fa] == 0) {
          ans[j] += lct.query(fa);
        }
        ans[j] += lct.querys(u);
        lct.link(u, ft[u]);
        ans[j] -= lct.query(u);
      }
    }
    for (int i = (int)mdf[x].size() - 1; i >= 0; i--) {
      int u = mdf[x][i].first;
      if (col[u] == 1) {
        lct.link(u, ft[u]);
        col[u] = 0;
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    ans[i] += ans[i - 1];
  }
  for (int i = 0; i <= q; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}