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 <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
inline int read() {
  int sum = 0, p = 1;
  char ch = getchar();
  while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
  if (ch == '-') p = -1, ch = getchar();
  while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
  return sum * p;
}
const int maxn = 4e5 + 20;
int col[maxn];
int n, fa[maxn], m;
vector<int> ed[maxn];
void dfs(int u) {
  for (int v : ed[u])
    if (v != fa[u]) fa[v] = u, dfs(v);
}
struct event {
  int tim, u, d;
};
vector<event> now[maxn];
inline void init() {
  n = read();
  m = read();
  for (int i = (1), _end_ = (n); i <= _end_; i++) col[i] = read();
  for (int i = (1), _end_ = (n - 1); i <= _end_; i++) {
    int u = read(), v = read();
    ed[u].push_back(v);
    ed[v].push_back(u);
  }
  dfs(1);
  fa[1] = n + 1;
  for (int i = (1), _end_ = (n); i <= _end_; i++)
    now[col[i]].push_back((event){0, i, 0});
  for (int i = (1), _end_ = (m); i <= _end_; i++) {
    int u = read(), x = read();
    now[col[u]].push_back((event){i, u, 1});
    now[col[u] = x].push_back((event){i, u, 0});
  }
  for (int i = (1), _end_ = (n); i <= _end_; i++)
    now[col[i]].push_back((event){m + 1, i, 1});
}
long long ans[maxn];
struct node {
  int fa, ch[2];
  int sz, si;
  long long sz2, si2;
};
node c[maxn];
inline bool isroot(int x) {
  return c[c[x].fa].ch[0] != x && c[c[x].fa].ch[1] != x;
}
inline void Merge(int x) {
  c[x].sz = c[(c[x].ch[0])].sz + c[(c[x].ch[1])].sz + c[x].si;
  c[x].sz2 = c[x].si2 + 1ll * c[(c[x].ch[0])].sz * c[(c[x].ch[0])].sz +
             1ll * c[(c[x].ch[1])].sz * c[(c[x].ch[1])].sz;
}
inline void rotate(int x) {
  int y = c[x].fa, z = c[y].fa, k = c[y].ch[1] == x;
  if (!isroot(y)) c[z].ch[c[z].ch[1] == y] = x;
  c[x].fa = z;
  c[y].ch[k] = c[x].ch[k ^ 1];
  c[c[y].ch[k]].fa = y;
  c[x].ch[k ^ 1] = y;
  c[y].fa = x;
  Merge(y);
  Merge(x);
}
inline void splay(int x) {
  while (!isroot(x)) {
    int y = c[x].fa, z = c[y].fa;
    if (!isroot(y))
      (c[y].ch[1] == x) ^ (c[z].ch[1] == y) ? rotate(x) : rotate(y);
    rotate(x);
  }
}
inline void access(int x) {
  for (int y = 0; x; y = x, x = c[x].fa) {
    splay(x);
    if ((c[x].ch[1]))
      c[x].si += c[(c[x].ch[1])].sz,
          c[x].si2 += 1ll * c[(c[x].ch[1])].sz * c[(c[x].ch[1])].sz;
    (c[x].ch[1]) = y;
    if ((c[x].ch[1]))
      c[x].si -= c[(c[x].ch[1])].sz,
          c[x].si2 -= 1ll * c[(c[x].ch[1])].sz * c[(c[x].ch[1])].sz;
    Merge(x);
  }
}
inline void link(int u, int fa) {
  access(fa);
  splay(fa);
  splay(u);
  c[u].fa = fa;
  c[fa].si += c[u].sz;
  c[fa].si2 += 1ll * c[u].sz * c[u].sz;
  Merge(fa);
}
inline void cut(int u, int fa) {
  access(u);
  access(fa);
  splay(fa);
  splay(u);
  c[u].fa = 0;
  c[fa].si -= c[u].sz;
  c[fa].si2 -= 1ll * c[u].sz * c[u].sz;
  Merge(fa);
}
inline int findroot(int x) {
  access(x);
  splay(x);
  while ((c[x].ch[0])) x = (c[x].ch[0]);
  splay(x);
  return x;
}
inline void doing() {
  for (int i = (1), _end_ = (n + 1); i <= _end_; i++)
    c[i].sz = c[i].si = 1, c[i].si2 = c[i].sz2 = 0;
  for (int i = (1), _end_ = (n); i <= _end_; i++)
    now[0].push_back((event){0, i, 1});
  for (event x : now[0]) {
    if (x.d == 1) {
      int u = x.u, fau = findroot(fa[u]);
      link(u, fa[u]);
    }
  }
  for (int COL = (1), _end_ = (n); COL <= _end_; COL++) {
    for (event x : now[COL]) {
      if (x.d == 1) {
        int u = x.u, fau = findroot(fa[u]);
        splay(u);
        ans[x.tim] -= c[u].sz2;
        splay(fau);
        ans[x.tim] -= c[fau].sz2;
        link(u, fa[u]);
        splay(fau);
        ans[x.tim] += c[fau].sz2;
      } else {
        int u = x.u, fau = findroot(fa[u]);
        splay(fau);
        ans[x.tim] -= c[fau].sz2;
        cut(u, fa[u]);
        splay(u);
        ans[x.tim] += c[u].sz2;
        splay(fau);
        ans[x.tim] += c[fau].sz2;
      }
    }
  }
  for (int i = (1), _end_ = (m); i <= _end_; i++) ans[i] += ans[i - 1];
  for (int i = (0), _end_ = (m); i <= _end_; i++) printf("%lld\n", -ans[i]);
}
int main() {
  init();
  doing();
  return 0;
}