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 mxn = 400010;
int rd() {
  int x = 0;
  char c = getchar();
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; x = x * 10 + c - 48, c = getchar())
    ;
  return x;
}
struct nd {
  int key, siz;
  long long num;
  bool tag;
  nd *ls, *rs, *fa;
} pool[mxn], *tpp = pool, *id[mxn], *stk[mxn];
bool noroot(nd *i) { return i->fa && (i->fa->ls == i || i->fa->rs == i); }
void pushup(nd *i) {
  i->siz = i->key;
  if (i->ls) i->siz += i->ls->siz;
  if (i->rs) i->siz += i->rs->siz;
}
void reverse(nd *i) {
  if (i) swap(i->ls, i->rs), i->tag ^= 1;
}
void pushdown(nd *i) {
  if (i->tag) reverse(i->ls), reverse(i->rs), i->tag = 0;
}
void rotate(nd *i) {
  nd *f = i->fa, *s;
  if (noroot(f))
    if (f->fa->ls == f)
      f->fa->ls = i;
    else
      f->fa->rs = i;
  else
    ;
  i->fa = f->fa, f->fa = i;
  if (f->ls == i)
    f->ls = s = i->rs, i->rs = f;
  else
    f->rs = s = i->ls, i->ls = f;
  if (s) s->fa = f;
  pushup(f), pushup(i);
}
void splay(nd *x, int tp = 1) {
  stk[1] = x;
  for (nd *y = x; noroot(y); stk[++tp] = y = y->fa)
    ;
  for (; tp; pushdown(stk[tp--]))
    ;
  for (nd *y; noroot(x); rotate(x))
    if (noroot(y = x->fa)) rotate((y->fa->ls == y) ^ (y->ls == x) ? x : y);
}
void add(nd *x, nd *y) {
  if (x) y->key += x->siz, y->siz += x->siz, y->num += 1ll * x->siz * x->siz;
}
void del(nd *x, nd *y) {
  if (x) y->key -= x->siz, y->siz -= x->siz, y->num -= 1ll * x->siz * x->siz;
}
void access(nd *x) {
  for (nd *y = 0; x; x = (y = x)->fa)
    splay(x), del(y, x), add(x->rs, x), x->rs = y, pushup(x);
}
nd *findroot(nd *x) {
  access(x), splay(x);
  for (pushdown(x); x->ls; pushdown(x = x->ls))
    ;
  return splay(x), x;
}
void link(nd *x, nd *y) { splay(x), access(y), splay(y), add(x, y), x->fa = y; }
void cut(nd *x, nd *y) { access(y), splay(y), splay(x), del(x, y), x->fa = 0; }
int n, m, q, tot, head[mxn], fa[mxn], col[mxn];
long long ans[mxn];
struct ed {
  int to, nxt;
} edge[mxn << 1];
void addedge(int u, int v) {
  edge[++m] = (ed){v, head[u]}, head[u] = m;
  edge[++m] = (ed){u, head[v]}, head[v] = m;
}
void dfs(int u, int f) {
  fa[u] = f;
  for (int i = head[u], v; i; i = edge[i].nxt)
    if ((v = edge[i].to) != f) dfs(v, u);
}
struct opr {
  int typ, x, col, tim;
} a[mxn << 2];
bool operator<(const opr x, const opr y) {
  return x.col < y.col || (x.col == y.col && x.tim < y.tim);
}
int main() {
  n = rd(), q = rd();
  for (int i = 1; i <= n; ++i) a[++tot] = (opr){1, i, col[i] = rd(), 0};
  for (int i = 1, x, y; i < n; ++i) x = rd(), y = rd(), addedge(x, y);
  dfs(1, 0);
  id[0] = ++tpp;
  for (int i = 1; i <= n; ++i) id[i] = ++tpp, tpp->key = 1, tpp->siz = 1;
  for (int i = 1; i <= n; ++i) link(id[i], id[fa[i]]);
  for (int i = 1; i <= q; ++i) {
    int x = rd(), y = rd();
    if (col[x] == y) continue;
    a[++tot] = (opr){0, x, col[x], i};
    a[++tot] = (opr){1, x, col[x] = y, i};
  }
  sort(a + 1, a + tot + 1);
  int lst = 0;
  for (int i = 1; i <= tot; ++i) {
    if (a[i].col > a[i - 1].col) {
      for (int j = i - 1; j > lst; --j)
        if (a[j].typ)
          link(id[a[j].x], id[fa[a[j].x]]);
        else
          cut(id[a[j].x], id[fa[a[j].x]]);
      lst = i - 1;
    }
    if (a[i].typ) {
      nd *x = id[a[i].x], *y = id[fa[a[i].x]], *z;
      if ((z = findroot(x)->rs)) ans[a[i].tim] += 1ll * z->siz * z->siz;
      cut(x, y);
      access(x), ans[a[i].tim] -= x->num;
      if ((z = findroot(y)->rs)) ans[a[i].tim] -= 1ll * z->siz * z->siz;
    } else {
      nd *x = id[a[i].x], *y = id[fa[a[i].x]], *z;
      access(x), ans[a[i].tim] += x->num;
      if ((z = findroot(y)->rs)) ans[a[i].tim] += 1ll * z->siz * z->siz;
      link(x, y);
      if ((z = findroot(x)->rs)) ans[a[i].tim] -= 1ll * z->siz * z->siz;
    }
  }
  for (int i = 1; i <= q; ++i) ans[i] += ans[i - 1];
  for (int i = 0; i <= q; ++i) printf("%I64d\n", ans[i]);
  return 0;
}