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 nxt[500010 << 1], to[500010 << 1], head[500010], cnt;
int n, m;
struct LCT {
  int ch[500010][2], fa[500010], cnt;
  long long val[500010], sum[500010], s[500010];
  void init(int n) {
    for (int i = 1; i <= n; i++) s[i] = 1;
  }
  bool is_root(int u) {
    return !fa[u] || (ch[fa[u]][0] != u && ch[fa[u]][1] != u);
  }
  void update(int u) {
    s[u] = val[u] + 1;
    if (ch[u][0]) s[u] += s[ch[u][0]];
    if (ch[u][1]) s[u] += s[ch[u][1]];
  }
  void rotate(int u) {
    int f = fa[u], ff = fa[f];
    int k = ch[f][1] == u, v = ch[u][!k];
    if (!is_root(f)) ch[ff][ch[ff][1] == f] = u;
    ch[f][k] = v;
    ch[u][!k] = f;
    if (v) fa[v] = f;
    fa[f] = u;
    fa[u] = ff;
    update(f), update(u);
  }
  void splay(int x) {
    while (!is_root(x)) {
      int f = fa[x], ff = fa[f];
      if (!is_root(f)) rotate((ch[ff][1] == f) ^ (ch[f][1] == x) ? x : f);
      rotate(x);
    }
  }
  void access(int x) {
    for (int y = 0; x; y = x, x = fa[x]) {
      splay(x);
      int &v = ch[x][1];
      if (v) val[x] += s[v], sum[x] += 1ll * s[v] * s[v];
      v = y;
      if (v) val[x] -= s[v], sum[x] -= 1ll * s[v] * s[v];
    }
  }
  int find_root(int x) {
    access(x);
    splay(x);
    while (ch[x][0]) x = ch[x][0];
    splay(x);
    return x;
  }
  void link(int x, int y) {
    access(y);
    splay(y);
    splay(x);
    fa[x] = y;
    val[y] += s[x];
    sum[y] += 1ll * s[x] * s[x];
    update(y);
  }
  void cut(int x, int y) {
    access(y);
    splay(y);
    splay(x);
    fa[x] = 0;
    val[y] -= s[x];
    sum[y] -= 1ll * s[x] * s[x];
    update(y);
  }
} t;
int fa[500010];
void dfs(int u, int pre) {
  fa[u] = pre;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != pre) dfs(to[i], u);
}
void add(int u, int v) {
  nxt[++cnt] = head[u];
  to[cnt] = v;
  head[u] = cnt;
}
vector<pair<int, int> > q[500010];
bool df[500010];
long long answer(int u) {
  int f = t.find_root(u);
  if (df[f])
    return 1l * t.s[t.ch[f][1]] * t.s[t.ch[f][1]];
  else
    return 1ll * t.s[f] * t.s[f];
}
long long change(int u) {
  df[u] ^= 1;
  if (df[u]) {
    if (u == 1) {
      t.access(1);
      return t.sum[1] - 1ll * t.s[1] * t.s[1];
    }
    long long r = -answer(u);
    t.cut(u, fa[u]);
    t.access(u);
    r += t.sum[u];
    if (!df[fa[u]]) r += answer(fa[u]);
    return r;
  } else {
    if (u == 1) {
      t.access(1);
      return 1ll * t.s[1] * t.s[1] - t.sum[1];
    }
    t.access(u);
    long long r = -t.sum[u];
    if (!df[fa[u]]) r -= answer(fa[u]);
    t.link(u, fa[u]);
    r += answer(u);
    return r;
  }
}
long long ans[500010];
void solve(int col) {
  for (int i = 0; i < q[col].size(); i++)
    ans[q[col][i].first] += change(q[col][i].second);
  for (int i = (int)q[col].size() - 1; i >= 0; i--) change(q[col][i].second);
}
int col[500010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v), add(v, u);
  }
  dfs(1, 0);
  t.init(n);
  for (int i = 1; i <= n; i++) t.link(i, fa[i]);
  for (int i = 1; i <= n; i++) q[col[i]].push_back(make_pair(0, i));
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    q[col[u]].push_back(make_pair(i, u));
    col[u] = v;
    q[col[u]].push_back(make_pair(i, u));
  }
  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++) printf("%lld\n", -ans[i]);
  return 0;
}