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 = 4e5 + 2;
int n, m, c[mxN], p[mxN];
vector<int> adj[mxN];
vector<array<int, 3>> td[mxN];
long long ans, d[mxN];
struct linkcut {
  int p[mxN], pp[mxN], c[mxN][2];
  int s[mxN], se[mxN];
  long long s2e[mxN];
  void cmb(int u) { s[u] = s[c[u][0]] + 1 + s[c[u][1]] + se[u]; }
  int ci(int u) { return c[p[u]][1] == u; }
  void cn(int u, int v, int i) {
    if (u) p[u] = v;
    if (v) c[v][i] = u;
  }
  void ro(int u) {
    int v = p[u], i = ci(u), w = p[v], j = ci(v);
    cn(c[u][!i], v, i);
    cn(v, u, !i);
    cn(u, w, j);
    swap(pp[u], pp[v]);
    cmb(v);
    cmb(u);
  }
  int spl(int u) {
    while (p[p[u]]) {
      ro(ci(u) ^ ci(p[u]) ? u : p[u]);
      ro(u);
    }
    if (p[u]) ro(u);
    return u;
  }
  void dc(int u, int i) {
    p[c[u][i]] = 0;
    c[u][i] = 0;
  }
  void ppc(int u, int v) {
    if (!u || !v) return;
    se[v] += s[u];
    s2e[v] += (long long)s[u] * s[u];
    pp[u] = v;
  }
  void ppd(int u) {
    se[pp[u]] -= s[u];
    s2e[pp[u]] -= (long long)s[u] * s[u];
    pp[u] = 0;
  }
  int xp(int u) {
    for (int v = u, w = 0; v; w = v, v = pp[v]) {
      spl(v);
      ppc(c[v][1], v);
      dc(v, 1);
      ppd(w);
      cn(w, v, 1);
      cmb(v);
    }
    return spl(u);
  }
  void lk(int u, int v) {
    ppc(spl(u), xp(v));
    cmb(v);
  }
  void ct(int u) {
    dc(xp(u), 0);
    cmb(u);
  }
  int gf(int u) { return c[u][0] ? gf(c[u][0]) : u; }
  int gr(int u) { return spl(gf(xp(u))); }
} lc;
void dfs(int u = 1) {
  for (int v : adj[u]) {
    if (v ^ p[u]) {
      p[v] = u;
      dfs(v);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  lc.s[1] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
    td[c[i]].push_back({0, i, 0});
    lc.s[i + 1] = 1;
  }
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1, u, x; i <= m; ++i) {
    cin >> u >> x;
    td[c[u]].push_back({i, u, 1});
    c[u] = x;
    td[c[u]].push_back({i, u, 0});
  }
  dfs();
  for (int i = 1; i <= n; ++i) lc.lk(i + 1, p[i] + 1);
  auto gg = [](int u) { return lc.s2e[lc.xp(lc.gr(u + 1))]; };
  for (int i = 1; i <= n; ++i) {
    for (array<int, 3> a : td[i]) {
      if (a[2]) {
        d[a[0]] += gg(a[1]) + gg(p[a[1]]);
        lc.lk(a[1] + 1, p[a[1]] + 1);
        d[a[0]] -= gg(a[1]);
      } else {
        d[a[0]] += gg(a[1]);
        lc.ct(a[1] + 1);
        d[a[0]] -= gg(a[1]) + gg(p[a[1]]);
      }
    }
    for (array<int, 3> a : td[i]) {
      lc.ct(a[1] + 1);
      lc.lk(a[1] + 1, p[a[1]] + 1);
    }
  }
  for (int i = 0; i <= m; ++i) cout << (ans += d[i]) << "\n";
}