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>
const long long md = 998244353;
inline long long fmul(long long x, long long y, const long long P) {
  return (x * y) % P;
}
inline long long fpw(long long x, long long y, const long long modol) {
  if (x == modol - 1) return y & 1 ? modol - 1 : 1;
  long long res = 1;
  while (y) {
    if (y & 1) res = fmul(res, x, modol);
    x = fmul(x, x, modol);
    y >>= 1;
  }
  return res % modol;
}
long long exgcd(long long& x, long long& y, long long a, long long b) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long res = exgcd(y, x, b, a % b);
  y -= x * (a / b);
  return res;
}
inline long long ad(long long x, long long y, const long long md) {
  return x + y >= md ? x + y - md : x + y;
}
inline long long sub(long long x, long long y, const long long md) {
  return x < y ? md + x - y : x - y;
}
inline long long inv(long long o, const long long modol) {
  long long x, y;
  exgcd(x, y, o, modol);
  x = (x % modol + modol) % md;
  return x;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
long long mmax(long long x, long long y) { return x > y ? x : y; }
long long mmin(long long x, long long y) { return x < y ? x : y; }
const int N = 4e5 + 10;
int n, m, f[N], head[N], pos;
struct edge {
  int nxt, to;
} e[N << 1];
void add(int u, int v) {
  e[++pos] = (edge){head[u], v};
  head[u] = pos;
}
void dfs(int u, int fa) {
  int i;
  f[u] = fa;
  for (i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, u);
  }
}
long long ans;
namespace lct {
struct node {
  int f_, ch[2];
  long long siz, si, si2;
} tr[N];
bool isrt(int u) { return tr[tr[u].f_].ch[0] != u && tr[tr[u].f_].ch[1] != u; }
int gt(int u) { return tr[tr[u].f_].ch[1] == u; }
void pushup(int u) {
  tr[u].siz = tr[tr[u].ch[0]].siz + tr[tr[u].ch[1]].siz + tr[u].si + 1;
}
void rotate(int D) {
  int B = tr[D].f_, A = tr[B].f_, w1 = gt(D), w2 = gt(B);
  if (!isrt(B)) tr[A].ch[w2] = D;
  tr[B].ch[w1] = tr[D].ch[w1 ^ 1];
  tr[tr[D].ch[w1 ^ 1]].f_ = B;
  tr[D].ch[w1 ^ 1] = B;
  tr[B].f_ = D;
  tr[D].f_ = A;
  pushup(B);
  pushup(D);
}
void splay(int u) {
  for (int ft = tr[u].f_; !isrt(u); rotate(u), ft = tr[u].f_) {
    if (!isrt(ft)) rotate(gt(ft) == gt(u) ? ft : u);
  }
  pushup(u);
}
void access(int u) {
  for (int y = 0; u; y = u, u = tr[u].f_) {
    splay(u);
    tr[u].si += tr[tr[u].ch[1]].siz - tr[y].siz;
    tr[u].si2 +=
        tr[tr[u].ch[1]].siz * tr[tr[u].ch[1]].siz - tr[y].siz * tr[y].siz;
    tr[u].ch[1] = y;
    pushup(u);
  }
}
int fd(int u) {
  access(u);
  splay(u);
  while (tr[u].ch[0]) u = tr[u].ch[0];
  return u;
}
void link(int x) {
  access(x);
  splay(x);
  ans -= tr[x].si2 + tr[tr[x].ch[1]].siz * tr[tr[x].ch[1]].siz;
  int tmp = fd(f[x]);
  splay(tmp);
  ans -= tr[tmp].si2 + tr[tr[tmp].ch[1]].siz * tr[tr[tmp].ch[1]].siz;
  int y = f[x];
  access(y);
  splay(y);
  tr[x].f_ = y;
  tr[y].si += tr[x].siz;
  tr[y].si2 += tr[x].siz * tr[x].siz;
  pushup(y);
  tmp = fd(y);
  splay(tmp);
  ans += tr[tmp].si2 + tr[tr[tmp].ch[1]].siz * tr[tr[tmp].ch[1]].siz;
}
void cut(int x) {
  int y = f[x];
  int tmp = fd(y);
  splay(tmp);
  ans -= tr[tmp].si2 + tr[tr[tmp].ch[1]].siz * tr[tr[tmp].ch[1]].siz;
  access(x);
  splay(x);
  ans += tr[x].si2;
  tr[tr[x].ch[0]].f_ = 0;
  tr[x].ch[0] = 0;
  pushup(x);
  tmp = fd(y);
  splay(tmp);
  ans += tr[tmp].si2 + tr[tr[tmp].ch[1]].siz * tr[tr[tmp].ch[1]].siz;
}
}  // namespace lct
int c[N];
std::vector<std::pair<int, int> > op[N];
std::vector<int> ini[N];
int tag[N];
long long res[N];
std::set<int> s;
int main() {
  n = read();
  m = read();
  int i;
  for (i = 1; i <= n + 1; ++i) lct::tr[i].siz = 1;
  for (i = 1; i <= n; ++i) c[i] = read();
  for (i = 2; i <= n; ++i) {
    int x, y;
    x = read();
    y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  f[1] = n + 1;
  for (i = 1; i <= n; ++i) ini[c[i]].push_back(i);
  for (i = 1; i <= m; ++i) {
    int u = read();
    int x = read();
    op[c[u]].push_back(std::make_pair(u, i));
    op[x].push_back(std::make_pair(u, i));
    c[u] = x;
  }
  for (i = 1; i <= n; ++i) lct::link(i);
  for (i = 1; i <= n; ++i) {
    std::vector<int>::iterator it;
    for (it = ini[i].begin(); it != ini[i].end(); ++it) {
      lct::cut(*it);
      tag[*it] = 1;
      s.insert(*it);
    }
    std::vector<std::pair<int, int> >::iterator it1;
    int pre = 0;
    for (it1 = op[i].begin(); it1 != op[i].end(); it1++) {
      res[pre] += (long long)n * (long long)n - ans;
      res[(it1->second)] -= (long long)n * (long long)n - ans;
      pre = it1->second;
      if (tag[it1->first]) {
        lct::link(it1->first);
        tag[it1->first] = 0;
        s.erase(s.lower_bound(it1->first));
      } else {
        lct::cut(it1->first);
        tag[it1->first] = 1;
        s.insert(it1->first);
      }
    }
    if (pre <= m)
      res[pre] += (long long)n * (long long)n - ans,
          res[m + 1] -= (long long)n * (long long)n - ans;
    std::set<int>::iterator it2;
    for (it2 = s.begin(); it2 != s.end(); ++it2) {
      tag[*it2] = 0;
      lct::link(*it2);
    }
    s.clear();
  }
  for (i = 1; i <= m; ++i) res[i] += res[i - 1];
  for (i = 0; i <= m; ++i) printf("%lld\n", res[i]);
}