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;
using pii = pair<int, int>;
using INT = long long;
bool now[404040];
int fa[404040], c[404040];
int pa[404040], son[404040][2];
INT s2[404040], del[404040], ans;
int vir[404040], sz[404040];
vector<pii> vec[404040];
vector<int> adj[404040];
void push_up(int u) { sz[u] = sz[son[u][0]] + sz[son[u][1]] + vir[u] + 1; }
bool is_root(int u) { return son[pa[u]][0] != u && son[pa[u]][1] != u; }
void rot(int first, bool d) {
  int second = pa[first], z = pa[second];
  son[second][!d] = son[first][d];
  pa[son[first][d]] = second, pa[first] = pa[second];
  if (son[z][0] == second)
    son[z][0] = first;
  else if (son[z][1] == second)
    son[z][1] = first;
  pa[second] = first, son[first][d] = second;
  push_up(second);
}
void splay(int first) {
  int second, z;
  bool d;
  while (!is_root(first)) {
    if (is_root(pa[first]))
      rot(first, son[pa[first]][0] == first);
    else {
      second = pa[first], z = pa[second], d = son[z][0] == second;
      son[second][d] == first ? rot(first, !d) : rot(second, d);
      rot(first, d);
    }
  }
  push_up(first);
}
void access(int first) {
  for (int second = 0; first; first = pa[first]) {
    splay(first);
    vir[first] += sz[son[first][1]],
        s2[first] += ((INT)(sz[son[first][1]]) * (sz[son[first][1]]));
    son[first][1] = second, vir[first] -= sz[second],
    s2[first] -= ((INT)(sz[second]) * (sz[second]));
    push_up(second = first);
  }
}
int get_root(int u) {
  access(u), splay(u);
  while (son[u][0]) u = son[u][0];
  return u;
}
void link(int u) {
  splay(u), ans -= ((INT)(sz[son[u][1]]) * (sz[son[u][1]])) + s2[u];
  int first = get_root(fa[u]);
  splay(first);
  int up = sz[son[first][1]];
  ans += ((INT)(up + sz[u]) * (up + sz[u])) - ((INT)(up) * (up));
  pa[u] = fa[u], vir[fa[u]] += sz[u];
  s2[fa[u]] += ((INT)(sz[u]) * (sz[u])), access(u);
}
void cut(int u) {
  int first = get_root(u);
  splay(first);
  int up = sz[son[first][1]];
  ans +=
      s2[u] + ((INT)(up - vir[u] - 1) * (up - vir[u] - 1)) - ((INT)(up) * (up));
  splay(u), pa[son[u][0]] = 0, son[u][0] = 0;
}
void dfs(int u) {
  link(u);
  for (int v : adj[u])
    if (v != fa[u]) {
      fa[v] = u, dfs(v);
    }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", c + i), vec[c[i]].push_back({i, 0});
  }
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v), adj[v].push_back(u);
  }
  for (int i = 1, u; i <= m; i++) {
    scanf("%d", &u), vec[c[u]].push_back({u, i});
    scanf("%d", c + u), vec[c[u]].push_back({u, i});
  }
  fa[1] = n + 1, dfs(1);
  for (int c = 1, u; c <= n; c++) {
    if (vec[c].empty()) {
      del[0] += ((INT)(n) * (n));
      continue;
    }
    INT pre = 0;
    if (vec[c][0].second) pre = ((INT)(n) * (n)), del[0] += pre;
    for (int i = 0, j = 0; i < vec[c].size(); i = j) {
      for (; j < vec[c].size() && vec[c][i].second == vec[c][j].second; j++) {
        u = vec[c][j].first;
        if (now[u] ^= 1)
          cut(u);
        else
          link(u);
      }
      del[vec[c][i].second] += ans - pre, pre = ans;
    }
    for (pii p : vec[c]) {
      u = p.first;
      if (now[u] ^= 1)
        cut(u);
      else
        link(u);
    }
  }
  ans = ((INT)(n) * (n)) * n;
  for (int i = 0; i <= m; i++) {
    printf("%I64d\n", ans -= del[i]);
  }
}