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 MAXN = 5e5 + 7;
template <typename T>
inline T read() {
  T res = 0, flag = 1;
  char in = getchar();
  while (!isdigit(in)) {
    if (in == '-') flag = -1;
    in = getchar();
  }
  while (isdigit(in)) {
    res = (res << 1) + (res << 3) + in - '0';
    in = getchar();
  }
  return res * flag;
}
template <typename T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
inline long long D(int first) { return (long long)first * first; }
int n, Q;
long long ans;
int fa[MAXN];
namespace LCT {
int f[MAXN], ch[MAXN][2];
int siz[MAXN], is[MAXN];
long long siz2[MAXN], is2[MAXN];
inline bool nroot(int first) {
  return (ch[f[first]][0]) == first || (ch[f[first]][1]) == first;
}
inline void pushup(int first) {
  siz[first] = 1 + siz[(ch[first][0])] + siz[(ch[first][1])] + is[first];
  siz2[first] = is2[first] + D(siz[(ch[first][0])]) + D(siz[(ch[first][1])]);
}
inline void rotate(int first) {
  int y = f[first];
  int z = f[y];
  int k = first == (ch[y][1]);
  if (nroot(y)) ch[z][(ch[z][1]) == y] = first;
  f[y] = first;
  ch[y][k] = ch[first][k ^ 1];
  f[first] = z;
  if (ch[first][k ^ 1]) f[ch[first][k ^ 1]] = y;
  ch[first][k ^ 1] = y;
  pushup(y);
  pushup(first);
}
inline void splay(int first) {
  while (nroot(first)) {
    int y = f[first];
    int z = f[y];
    if (nroot(y))
      rotate((((ch[y][0]) == first) ^ ((ch[z][0]) == y)) ? first : y);
    rotate(first);
  }
}
inline void access(int first) {
  for (int y = 0; first; first = f[y = first]) {
    splay(first);
    is2[first] -= D(siz[y]);
    is2[first] += D(siz[(ch[first][1])]);
    is[first] -= siz[y];
    is[first] += siz[(ch[first][1])];
    (ch[first][1]) = y;
    pushup(first);
  }
}
inline int findroot(int first) {
  int y = first;
  splay(first);
  for (; first; first = (ch[y = first][0]))
    ;
  return y;
}
inline void Link(int first) {
  access(first);
  splay(first);
  ans -= siz2[first];
  int F = fa[first];
  access(F);
  int y = findroot(F);
  splay(y);
  ans -= D(siz[(ch[y][1])]);
  splay(F);
  f[first] = F;
  is2[F] += D(siz[first]);
  is[F] += siz[first];
  pushup(F);
  access(first);
  splay(y);
  ans += D(siz[(ch[y][1])]);
}
inline void Cut(int first) {
  access(first);
  ans += is2[first];
  int y = findroot(first);
  splay(y);
  ans -= D(siz[(ch[y][1])]);
  int F = fa[first];
  splay(first);
  (ch[first][0]) = f[(ch[first][0])] = 0;
  pushup(first);
  splay(y);
  ans += D(siz[(ch[y][1])]);
}
}  // namespace LCT
int col[MAXN];
bool ky[MAXN];
vector<pair<int, int> > opr[MAXN];
long long dt[MAXN];
int dex, head[MAXN], to[MAXN << 1], nxt[MAXN << 1];
inline void Add(int first, int y) {
  nxt[++dex] = head[first];
  to[dex] = y;
  head[first] = dex;
}
void dfs(int u) {
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
  }
}
inline void init() {
  n = read<int>();
  Q = read<int>();
  for (int i = 1; i <= n; ++i) {
    int c = read<int>();
    col[i] = c;
    opr[c].push_back(make_pair(i, 0));
  }
  for (int i = 1; i < n; ++i) {
    int u = read<int>();
    int v = read<int>();
    Add(u, v);
    Add(v, u);
  }
  fa[1] = n + 1;
  dfs(1);
  for (int i = 1; i <= Q; ++i) {
    int u = read<int>();
    int c = read<int>();
    opr[col[u]].push_back(make_pair(u, i));
    opr[col[u] = c].push_back(make_pair(u, i));
  }
  for (int i = 1; i <= n; ++i) LCT::Link(i);
}
inline void solve() {
  long long Last = 0;
  ky[n + 1] = 1;
  for (int i = 1; i <= n; ++i) {
    if (!opr[i].size()) {
      dt[0] += D(n);
      continue;
    }
    if (opr[i][0].second) {
      Last = D(n);
      dt[0] += Last;
    } else
      Last = 0;
    int len = opr[i].size();
    for (int j = 0; j < len; ++j) {
      int u = opr[i][j].first;
      if (ky[u])
        LCT::Link(u);
      else
        LCT::Cut(u);
      ky[u] ^= 1;
      if (j == len - 1 || opr[i][j].second != opr[i][j + 1].second) {
        dt[opr[i][j].second] += ans - Last;
        Last = ans;
      }
    }
    for (int j = 0; j < len; ++j) {
      int u = opr[i][j].first;
      if (ky[u]) {
        LCT::Link(u);
        ky[u] = 0;
      }
    }
  }
  ans = D(n) * n;
  for (int i = 0; i <= Q; ++i) {
    ans -= dt[i];
    printf("%I64d\n", ans);
  }
}
int main() {
  init();
  solve();
  return 0;
}