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>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __zz = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__zz] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__zz], --__zz)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
}  // namespace my_std
using namespace my_std;
int n, m;
int col[404004];
struct hh {
  int t, nxt;
} edge[404004 << 1];
int head[404004], ecnt;
void make_edge(int f, int t) {
  edge[++ecnt] = (hh){t, head[f]};
  head[f] = ecnt;
  edge[++ecnt] = (hh){f, head[t]};
  head[t] = ecnt;
}
int f[404004];
void dfs(int x, int fa) {
  f[x] = fa;
  for (int i = head[x]; i; i = edge[i].nxt)
    if (edge[i].t != fa) dfs(edge[i].t, x);
}
int nc[404004];
namespace LCT {
int fa[404004], s[404004], size[404004], ch[404004][2], tag[404004], rt[404004];
long long sq[404004];
int get(int x) { return ch[fa[x]][1] == x; }
int nroot(int x) { return ch[fa[x]][0] == x || ch[fa[x]][1] == x; }
void pushup(int x) {
  s[x] = (size[ch[x][0]] + s[ch[x][0]]) + (size[ch[x][1]] + s[ch[x][1]]) + 1;
  if (ch[x][0])
    rt[x] = rt[ch[x][0]];
  else
    rt[x] = x;
}
void Rev(int x) {
  tag[x] ^= 1;
  swap(ch[x][0], ch[x][1]);
}
void pushdown(int x) {
  if (!tag[x]) return;
  if (ch[x][0]) Rev(ch[x][0]);
  if (ch[x][1]) Rev(ch[x][1]);
  tag[x] = 0;
}
void Pushdown(int x) {
  if (nroot(x)) Pushdown(fa[x]);
  pushdown(x);
}
void rotate(int x) {
  int y = fa[x], z = fa[y], k = get(x), w = ch[x][!k];
  if (nroot(y)) ch[z][get(y)] = x;
  ch[x][!k] = y;
  ch[y][k] = w;
  if (w) fa[w] = y;
  fa[y] = x;
  fa[x] = z;
  pushup(y), pushup(x);
}
void splay(int x) {
  Pushdown(x);
  for (int y; y = fa[x], nroot(x); rotate(x))
    if (nroot(y)) rotate(get(x) == get(y) ? y : x);
}
void access(int x) {
  for (int y = 0; x; x = fa[y = x])
    splay(x), size[x] += (size[ch[x][1]] + s[ch[x][1]]) - (size[y] + s[y]),
        sq[x] += (1ll * ((size[ch[x][1]] + s[ch[x][1]])) *
                  ((size[ch[x][1]] + s[ch[x][1]]))) -
                 (1ll * ((size[y] + s[y])) * ((size[y] + s[y]))),
        ch[x][1] = y, pushup(x);
}
long long calc(int x) {
  splay(x);
  return sq[x] + (1ll * ((size[ch[x][1]] + s[ch[x][1]])) *
                  ((size[ch[x][1]] + s[ch[x][1]])));
}
long long link(int x) {
  nc[x] = 0;
  int y = f[x];
  access(x), splay(x);
  access(y), splay(y);
  int root = rt[y];
  splay(root);
  long long ret = -calc(root) - calc(x);
  fa[x] = y;
  size[y] += (size[x] + s[x]);
  sq[y] += (1ll * ((size[x] + s[x])) * ((size[x] + s[x])));
  splay(y);
  ret += calc(root);
  return ret;
}
long long cut(int x) {
  nc[x] = 1;
  int y = f[x];
  access(x), splay(y);
  int root = rt[y];
  splay(root);
  long long ret = -calc(root);
  splay(y);
  ch[y][1] = fa[x] = 0;
  pushup(y);
  ret += calc(x);
  ret += calc(root);
  return ret;
}
}  // namespace LCT
using namespace LCT;
long long ans[404004];
vector<pair<int, int> > V[404004];
int main() {
  file();
  read(n, m);
  for (int i = (1); i <= (n); i++)
    read(col[i]), V[col[i]].push_back(make_pair(i, 0));
  int x, y;
  for (int i = (1); i <= (n - 1); i++) read(x, y), make_edge(x, y);
  dfs(1, 0);
  for (int i = (1); i <= (m); i++)
    read(x, y), V[col[x]].push_back(make_pair(x, i)),
        V[col[x] = y].push_back(make_pair(x, i));
  f[1] = n + 1;
  nc[n + 1] = 1;
  for (int i = (1); i <= (n); i++) pushup(i);
  for (int i = (1); i <= (n); i++) link(i);
  for (int c = (1); c <= (n); c++) {
    ans[0] += 1ll * n * n;
    for (auto w : V[c]) {
      int x = w.first;
      if (nc[x])
        ans[w.second] += link(x);
      else
        ans[w.second] += cut(x);
    }
    for (auto w : V[c])
      if (nc[w.first]) link(w.first);
  }
  for (int i = (1); i <= (m); i++) ans[i] += ans[i - 1];
  for (int i = (0); i <= (m); i++) printf("%I64d\n", 1ll * n * n * n - ans[i]);
  return 0;
}