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;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const long long INF = 2147483600;
const long long MAXN = 800010;
long long N, Q;
long long Node[MAXN << 1], Next[MAXN << 1], Root[MAXN << 1], cnt;
inline void insert(long long u, long long v) {
  Node[++cnt] = v;
  Next[cnt] = Root[u];
  Root[u] = cnt;
  return;
}
long long Fa[MAXN + 1];
long long ans = 0;
inline void dfs(long long k, long long F) {
  Fa[k] = F;
  for (long long x = Root[k]; x; x = Next[x]) {
    long long v = Node[x];
    if (v == Fa[k]) continue;
    dfs(v, k);
  }
}
namespace LCT {
long long sz[MAXN + 1], sta[MAXN + 1], top, fa[MAXN + 1];
long long ch[MAXN + 1][2];
long long szx[MAXN + 1], sz2[MAXN + 1];
bool rev[MAXN + 1];
inline void update(long long x) {
  sz[x] = sz[ch[x][0]] + 1 + sz[ch[x][1]] + szx[x];
}
inline bool chd(long long x) { return (ch[fa[x]][1] == x); }
inline bool nroot(long long x) {
  return (ch[fa[x]][0] == x || ch[fa[x]][1] == x);
}
inline void Con(long long son, long long F, long long x) {
  if (son == F) {
    puts("NO");
    exit(0);
  }
  ch[F][x] = son;
  fa[son] = F;
}
inline void rotate(long long x) {
  long long y = fa[x], z = fa[y];
  long long cx = chd(x), cy = chd(y);
  long long b = ch[x][cx ^ 1];
  if (nroot(y))
    Con(x, z, cy);
  else
    fa[x] = z;
  Con(y, x, (cx ^ 1));
  if (b)
    Con(b, y, cx);
  else
    ch[y][cx] = b;
  update(y);
  update(x);
}
inline void Color(long long x) {
  if (!x) return;
  rev[x] ^= 1;
  swap(ch[x][0], ch[x][1]);
}
inline void pushdown(long long x) {
  if (rev[x]) {
    Color(ch[x][0]);
    Color(ch[x][1]);
    rev[x] = 0;
  }
}
inline void Splay(long long x) {
  top = 0;
  long long y = x;
  sta[++top] = x;
  while (nroot(y)) sta[++top] = y = fa[y];
  while (top) pushdown(sta[top--]);
  while (nroot(x)) {
    y = fa[x];
    if (nroot(y)) rotate((chd(x) ^ chd(y)) ? x : y);
    rotate(x);
  }
  return;
}
inline void access(long long x) {
  for (long long y = 0; x; y = x, x = fa[x])
    Splay(x), szx[x] += sz[ch[x][1]] - sz[y],
        sz2[x] += sz[ch[x][1]] * sz[ch[x][1]] - sz[y] * sz[y], ch[x][1] = y,
                                                               update(x);
}
inline void chroot(long long x) {
  access(x);
  Splay(x);
  Color(x);
}
inline long long findroot(long long x) {
  access(x);
  Splay(x);
  while (ch[x][0]) x = ch[x][0];
  Splay(x);
  return x;
}
inline void Link(long long x, long long y) {
  Splay(x);
  ans -= sz2[x] + sz[ch[x][1]] * sz[ch[x][1]];
  long long z = findroot(y);
  access(x), Splay(z);
  ans -= sz[ch[z][1]] * sz[ch[z][1]];
  fa[x] = y;
  Splay(y);
  szx[y] += sz[x];
  sz2[y] += sz[x] * sz[x];
  update(y);
  access(x);
  Splay(z);
  ans += sz[ch[z][1]] * sz[ch[z][1]];
}
inline void Cut(long long x, long long y) {
  access(x);
  ans += sz2[x];
  long long z = findroot(x);
  access(x), Splay(z);
  ans -= sz[ch[z][1]] * sz[ch[z][1]];
  Splay(x);
  fa[ch[x][0]] = 0;
  ch[x][0] = 0;
  update(x);
  Splay(z);
  ans += sz[ch[z][1]] * sz[ch[z][1]];
}
}  // namespace LCT
using namespace LCT;
long long a[MAXN + 1], b[MAXN + 1];
vector<pair<long long, long long> > vec[MAXN + 1];
long long ad[MAXN + 1], lst = 0;
int main() {
  N = read(), Q = read();
  for (long long i = 1; i <= N; i++)
    b[i] = a[i] = read(), vec[a[i]].push_back(make_pair(i, 0));
  for (long long i = 1; i < N; i++) {
    long long u = read(), v = read();
    insert(u, v);
    insert(v, u);
  }
  for (long long i = 1; i <= Q; i++) {
    long long u = read(), x = read();
    if (b[u] == x) continue;
    vec[x].push_back(make_pair(u, i));
    vec[b[u]].push_back(make_pair(-u, i));
    b[u] = x;
  }
  dfs(1, N + 1);
  for (long long i = 1; i <= N; i++) Link(i, Fa[i]);
  for (long long i = 1; i <= N; i++) {
    long long l = vec[i].size();
    if (!l) {
      ad[0] += N * N;
      continue;
    }
    if (vec[i][0].second)
      ad[0] += N * N, lst = N * N;
    else
      lst = 0;
    for (long long j = 0; j < l; j++) {
      long long n = vec[i][j].first;
      long long tp = (n < 0 ? -1 : 1);
      n = abs(n);
      if (tp == -1)
        Link(n, Fa[n]);
      else
        Cut(n, Fa[n]);
      if (j == l - 1 || vec[i][j + 1].second != vec[i][j].second)
        ad[vec[i][j].second] += ans - lst, lst = ans;
    }
    for (long long j = l - 1; j >= 0; j--) {
      long long n = vec[i][j].first;
      long long tp = (n < 0 ? -1 : 1);
      n = abs(n);
      if (tp == -1) {
        Cut(n, Fa[n]);
      } else {
        Link(n, Fa[n]);
      }
    }
  }
  ans = N * N * N;
  for (long long i = 0; i <= Q; i++) ans -= ad[i], cout << ans << endl;
  return 0;
}