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;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
const long long MOD2 = (long long)998244353 * (long long)998244353;
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
vector<int> mp[400135];
int fa[400135], c[400135];
void dfs(int x, int pa) {
  fa[x] = pa;
  for (int c : mp[x])
    if (c != pa) dfs(c, x);
}
namespace LCT {
struct SplayNode {
  int sz = 1, szx = 0;
  long long s2 = 0;
} sn[400135];
const int N = 400135;
int ch[N][2];
int f[N];
void PushUp(int p) {
  sn[p].sz = 1 + sn[ch[p][0]].sz + sn[ch[p][1]].sz + sn[p].szx;
}
void Rotate(int x) {
  int y = f[x], z = f[y], k = (ch[f[x]][1] == x);
  if (!(ch[f[y]][0] != y && ch[f[y]][1] != y)) ch[z][ch[z][1] == y] = x;
  ch[y][k] = ch[x][!k];
  f[ch[y][k]] = y;
  ch[x][!k] = y;
  f[y] = x;
  f[x] = z;
  PushUp(y);
  PushUp(x);
}
inline void Update(int p) {
  if (!(ch[f[p]][0] != p && ch[f[p]][1] != p)) Update(f[p]);
}
void Splay(int x) {
  Update(x);
  for (int fa; (fa = f[x]) != 0 && !(ch[f[x]][0] != x && ch[f[x]][1] != x);
       Rotate(x)) {
    if (!(ch[f[fa]][0] != fa && ch[f[fa]][1] != fa))
      Rotate((ch[f[fa]][1] == fa) == (ch[f[x]][1] == x) ? fa : x);
  }
  PushUp(x);
}
int Access(int x) {
  int p;
  for (p = 0; x; p = x, x = f[x]) {
    Splay(x);
    sn[x].szx += sn[ch[x][1]].sz;
    sn[x].s2 += (long long)sn[ch[x][1]].sz * sn[ch[x][1]].sz;
    ch[x][1] = p;
    sn[x].szx -= sn[ch[x][1]].sz;
    sn[x].s2 -= (long long)sn[ch[x][1]].sz * sn[ch[x][1]].sz;
    PushUp(x);
  }
  return p;
}
void makeRoot(int p) {
  Access(p);
  Splay(p);
}
void path(int p, int q) {
  makeRoot(p);
  Access(q);
  Splay(q);
}
int Find(int p) {
  Access(p);
  Splay(p);
  while (ch[p][0]) {
    p = ch[p][0];
  }
  return p;
}
void link(int u, int v) {
  makeRoot(u);
  makeRoot(v);
  f[u] = v;
  sn[v].szx += sn[u].sz;
  sn[v].s2 += (long long)sn[u].sz * sn[u].sz;
  PushUp(v);
}
void cut(int u, int v) {
  Splay(u);
  Access(v);
  Splay(v);
  f[u] = 0;
  sn[v].szx -= sn[u].sz;
  sn[v].s2 -= (long long)sn[u].sz * sn[u].sz;
  PushUp(u);
  PushUp(v);
}
};  // namespace LCT
vector<pair<int, int> > col[400135];
long long ans[400135];
int vis[400135];
long long all(int x) {
  int t = LCT::Find(x);
  if (vis[t] == 0)
    return (long long)LCT::sn[t].sz * LCT::sn[t].sz;
  else {
    LCT::Access(t);
    LCT::Splay(t);
    return LCT::sn[t].s2;
  }
}
long long modify(int x) {
  vis[x] ^= 1;
  long long tmp = 0;
  int y = fa[x];
  if (vis[x] == 1) {
    tmp -= all(y);
    LCT::cut(x, y);
    LCT::Access(x);
    tmp += LCT::sn[x].s2;
    tmp += all(y);
  } else {
    LCT::Access(x);
    tmp -= LCT::sn[x].s2;
    tmp -= all(y);
    LCT::link(x, y);
    tmp += all(y);
  }
  return tmp;
}
void cal(int color) {
  for (auto& p : col[color]) {
    ans[p.first] += modify(p.second);
  }
  int N = col[color].size();
  for (int i = N - 1; ~i; i--) modify(col[color][i].second);
}
void fmain(int tid) {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", c + i);
  for (int i = 0, u, v; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
  };
  dfs(1, n + 1);
  vis[n + 1] = 1;
  LCT::sn[0].sz = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) LCT::link(i, fa[i]);
  for (int(i) = 1; (i) <= (int)(n); (i)++) col[c[i]].push_back({0, i});
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    int u, x;
    scanf("%d%d", &u, &x);
    col[c[u]].push_back({i, u});
    c[u] = x;
    col[x].push_back({i, u});
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) cal(i);
  printf("%lld\n", -ans[0]);
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    ans[i] += ans[i - 1];
    printf("%lld\n", -ans[i]);
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}