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;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 400005, K = 19;
int in[N], c[N], fa[N], out[N], top[N], wson[N], dp[N][K], dep[N], sz[N];
int n, m, ti;
long long ans[N], sz2[N], dq;
vector<int> v[N];
vector<pair<int, int> > co[N];
bool vis[N];
inline long long sqr(long long x) { return x * x; }
void dfs1(int p, int f) {
  dp[p][0] = fa[p] = f;
  sz[p] = 1;
  dep[p] = dep[f] + 1;
  for (auto i : v[p])
    if (i != f) {
      dfs1(i, p);
      sz[p] += sz[i];
      if (sz[i] > sz[wson[p]]) wson[p] = i;
    }
}
void dfs2(int p) {
  in[p] = ++ti;
  top[p] = wson[fa[p]] == p ? top[fa[p]] : p;
  if (wson[p]) dfs2(wson[p]);
  for (auto i : v[p])
    if (i != fa[p] && i != wson[p]) dfs2(i);
  out[p] = ti;
}
struct BIT {
  int c[N];
  inline int qiu(int pos) {
    if (!pos) return 0;
    int ans = 0;
    for (int i = pos; i < N; i += i & -i) ans += c[i];
    return ans;
  }
  inline void add(int pos, int de) {
    for (int i = pos; i; i -= i & -i) c[i] += de;
  }
  void add(int l, int r, int de) {
    add(l - 1, -de);
    add(r, de);
  }
} Sz, ef;
int getsz(int x) { return Sz.qiu(in[x]); }
long long getsz2(int x) {
  long long ans = sz2[x];
  if (wson[x] && vis[wson[x]] == 0) ans += sqr(getsz(wson[x]));
  return ans;
}
int get(int x) {
  for (int i = (int)(K - 1); i >= (int)(0); i--)
    if (dp[x][i] && ef.qiu(in[fa[x]]) == ef.qiu(in[dp[fa[x]][i]])) x = dp[x][i];
  return x;
}
void update(int x, int y, int de) {
  while (x && dep[x] >= dep[y]) {
    int t = top[x];
    if (dep[t] < dep[y]) t = y;
    if (fa[t] && vis[t] == 0 && wson[fa[t]] != t) {
      int zs = Sz.qiu(in[t]);
      sz2[fa[t]] -= sqr(zs);
      sz2[fa[t]] += sqr(zs + de);
    }
    Sz.add(in[t], in[x], de);
    x = fa[t];
  }
}
void cao(int x) {
  int t, jb, jj = getsz(x);
  if (vis[fa[x]])
    t = x;
  else
    t = get(fa[x]);
  update(fa[x], fa[t], (vis[x] ? 1 : -1) * jj);
  if (wson[fa[x]] != x) {
    sz2[fa[x]] += (vis[x] ? 1 : -1) * sqr(jj);
  }
  if (vis[fa[x]])
    jb = 0;
  else {
    jb = getsz(t);
    if (vis[x]) jb -= jj;
  }
  dq += (vis[x] ? 1 : -1) * (sqr(jb + jj) - sqr(jb) - getsz2(x));
  ef.add(in[x], out[x], vis[x] ? -1 : 1);
  vis[x] ^= 1;
}
int main() {
  vis[0] = 1;
  n = read(), m = read();
  for (int i = (int)(1); i <= (int)(n); i++)
    co[c[i] = read()].push_back(make_pair(i, 0));
  for (int i = (int)(2); i <= (int)(n); i++) {
    int s = read(), t = read();
    v[s].push_back(t);
    v[t].push_back(s);
  }
  dfs1(1, 0);
  dfs2(1);
  for (int i = (int)(1); i <= (int)(K - 1); i++)
    for (int j = (int)(1); j <= (int)(n); j++)
      dp[j][i] = dp[dp[j][i - 1]][i - 1];
  for (int i = (int)(1); i <= (int)(m); i++) {
    int u = read();
    co[c[u]].push_back(make_pair(u, i));
    co[c[u] = read()].push_back(make_pair(u, i));
  }
  for (int i = (int)(1); i <= (int)(n); i++)
    co[c[i]].push_back(make_pair(i, m + 1));
  dq = (long long)n * n;
  for (int i = (int)(1); i <= (int)(n); i++) {
    Sz.add(in[i], in[i], sz[i]);
    for (auto j : v[i])
      if (j != wson[i] && j != fa[i]) sz2[i] += sqr(sz[j]);
  }
  ans[0] = dq * n;
  for (int i = (int)(1); i <= (int)(n); i++) {
    for (auto j : co[i]) {
      long long dd = dq;
      cao(j.first);
      ans[j.second] += dq - dd;
    }
    assert(dq == (long long)n * n);
  }
  for (int i = (int)(0); i <= (int)(m); i++) {
    if (i) ans[i] += ans[i - 1];
    writeln((long long)n * n * n - ans[i]);
  }
}