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 N = 500100;
int c[2][N], fa[N], F[N], sz[N], val[N];
long long sum[N], now_res, ans[N];
bool it(int o) { return c[0][fa[o]] != o && c[1][fa[o]] != o; }
void ps(int o) { sz[o] = sz[c[0][o]] + sz[c[1][o]] + val[o]; }
void rot(int o) {
  int x = fa[o], k = c[0][x] == o;
  fa[c[!k][x] = c[k][o]] = x;
  fa[o] = fa[x];
  if (!it(x)) c[c[1][fa[x]] == x][fa[x]] = o;
  fa[c[k][o] = x] = o;
  ps(x);
}
void splay(int o) {
  for (; !it(o); rot(o))
    if (!it(fa[o]))
      rot((c[0][fa[o]] == o) ^ (c[0][fa[fa[o]]] == fa[o]) ? o : fa[o]);
  ps(o);
}
void acs(int o) {
  for (int y = 0; o; c[1][o] = y, ps(y = o), o = fa[o]) {
    splay(o);
    val[o] += sz[c[1][o]] - sz[y];
    sum[o] += (long long)sz[c[1][o]] * sz[c[1][o]] - (long long)sz[y] * sz[y];
  }
}
int fd(int o) {
  acs(o);
  splay(o);
  for (; c[0][o]; o = c[0][o])
    ;
  splay(o);
  return o;
}
void link(int x, int y) {
  acs(x);
  now_res += sum[x];
  int rt = fd(y);
  now_res += (long long)sz[c[1][rt]] * sz[c[1][rt]];
  fa[x] = y;
  splay(y);
  val[y] += sz[x];
  sum[y] += (long long)sz[x] * sz[x];
  sz[y] += sz[x];
  acs(x);
  splay(rt);
  now_res -= (long long)sz[c[1][rt]] * sz[c[1][rt]];
}
void cut(int x, int y) {
  int rt = fd(x);
  now_res += (long long)sz[c[1][rt]] * sz[c[1][rt]] - sum[x];
  splay(x);
  c[0][x] = fa[c[0][x]] = 0;
  ps(x);
  splay(rt);
  now_res -= (long long)sz[c[1][rt]] * sz[c[1][rt]];
}
vector<int> g[N];
void dfs(int x) {
  for (int i : g[x])
    if (i != F[x]) {
      F[i] = x;
      dfs(i);
    }
}
int n, m, col[N], vis[N];
vector<pair<int, int> > vec[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  now_res = (long long)n * n;
  for (int i = 1; i <= n; ++i) cin >> col[i], vec[col[i]].emplace_back(0, i);
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  g[n + 1].push_back(1);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    vec[col[x]].emplace_back(i, x);
    col[x] = y;
    vec[col[x]].emplace_back(i, x);
  }
  for (int i = 1; i <= n; ++i) vec[col[i]].emplace_back(m + 1, i);
  dfs(n + 1);
  for (int i = 1; i <= n + 1; ++i) val[i] = sz[i] = 1;
  for (int i = 1; i <= n; ++i) link(i, F[i]);
  for (int i = 1; i <= n; ++i) {
    long long res = 0;
    for (auto j : vec[i]) {
      if (vis[j.second])
        link(j.second, F[j.second]);
      else
        cut(j.second, F[j.second]);
      vis[j.second] ^= 1;
      ans[j.first] += now_res - res;
      res = now_res;
    }
  }
  for (int i = 1; i <= m; ++i) ans[i] += ans[i - 1];
  for (int i = 0; i <= m; ++i) cout << ans[i] << '\n';
  return 0;
}