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 read() {
  int a = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) {
    f = c == '-';
    c = getchar();
  }
  while (isdigit(c)) {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return f ? -a : a;
}
long long pw(int x) { return 1ll * x * x; }
const int _ = 5e5 + 7;
vector<int> nxt[_];
int N, M, tfa[_], tsz[_], col[_];
vector<pair<int, int> > mdf[_];
long long tsum[_], ans[_];
void dfs(int x, int p) {
  tfa[x] = p;
  tsz[x] = 1;
  for (auto t : nxt[x])
    if (t != p) {
      dfs(t, x);
      tsz[x] += tsz[t];
      tsum[x] += pw(tsz[t]);
    }
}
int ch[_][2], fa[_], sz[_], lsz[_];
long long lsum[_], val;
bool nroot(int x) { return ch[fa[x]][0] == x || ch[fa[x]][1] == x; }
bool son(int x) { return ch[fa[x]][1] == x; }
void upd(int x) { sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + lsz[x] + 1; }
void rot(int x) {
  bool f = son(x);
  int y = fa[x], z = fa[y], w = ch[x][f ^ 1];
  fa[x] = z;
  if (nroot(y)) ch[z][son(y)] = x;
  fa[y] = x;
  ch[x][f ^ 1] = y;
  ch[y][f] = w;
  if (w) fa[w] = y;
  upd(y);
}
void splay(int x) {
  while (nroot(x)) {
    if (nroot(fa[x])) {
      rot(son(fa[x]) == son(x) ? fa[x] : x);
    }
    rot(x);
  }
  upd(x);
}
void access(int x) {
  for (int y = 0; x; y = x, x = fa[x]) {
    splay(x);
    lsz[x] += sz[ch[x][1]] - sz[y];
    lsum[x] += pw(sz[ch[x][1]]) - pw(sz[y]);
    ch[x][1] = y;
  }
}
int fdrt(int x) {
  access(x);
  splay(x);
  while (ch[x][0]) {
    x = ch[x][0];
  }
  splay(x);
  return x;
}
void cut(int x) {
  int allsz = sz[ch[fdrt(x)][1]];
  splay(x);
  val = val - pw(allsz) + pw(allsz - lsz[x] - sz[ch[x][1]] - 1) + lsum[x] +
        pw(sz[ch[x][1]]);
  ch[x][0] = fa[ch[x][0]] = 0;
  upd(x);
}
void link(int x) {
  int f = tfa[x], upsz = sz[ch[fdrt(f)][1]];
  splay(x);
  splay(f);
  val = val - lsum[x] - pw(sz[ch[x][1]]) - pw(upsz) + pw(sz[x] + upsz);
  fa[x] = f;
  lsz[f] += sz[x];
  sz[f] += sz[x];
  lsum[f] += pw(sz[x]);
}
int main() {
  N = read();
  M = read();
  for (int i = 1; i <= N; ++i) {
    col[i] = read();
    mdf[col[i]].push_back(make_pair(0, i));
  }
  for (int i = 1; i < N; ++i) {
    int p = read(), q = read();
    nxt[p].push_back(q);
    nxt[q].push_back(p);
  }
  nxt[N + 1] = {1};
  dfs(N + 1, 0);
  for (int i = 1; i <= N + 1; ++i) {
    fa[i] = tfa[i];
    sz[i] = tsz[i];
    lsz[i] = tsz[i] - 1;
    lsum[i] = tsum[i];
  }
  for (int i = 1; i <= M; ++i) {
    int p = read(), q = read();
    mdf[col[p]].push_back(make_pair(i, -p));
    mdf[col[p] = q].push_back(make_pair(i, p));
  }
  val = pw(N);
  for (int i = 1; i <= N; ++i) {
    int pre = 0;
    for (auto t : mdf[i]) {
      ans[pre] += pw(N) - val;
      ans[t.first] -= pw(N) - val;
      t.second > 0 ? cut(t.second) : link(-t.second);
      pre = t.first;
    }
    ans[pre] += pw(N) - val;
    reverse(mdf[i].begin(), mdf[i].end());
    for (auto t : mdf[i]) t.second > 0 ? link(t.second) : cut(-t.second);
  }
  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;
}