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;
long long int ans = 0;
struct Node {
  long long int left, right, parent;
  long long int key, id, size, size2, vir, vir2;
  Node(long long int k = 0, long long int i = 0) {
    left = right = parent = size = size2 = vir = vir2 = 0;
    key = k;
    id = i;
  }
  bool operator<(Node& A) { return key < A.key || (key == A.key && id < A.id); }
  bool operator==(Node& A) { return id == A.id; }
} node[600000];
struct LinkCutTree {
  bool nroot(long long int j) {
    assert(j);
    long long int p = node[j].parent;
    return p && (node[p].left == j || node[p].right == j);
  }
  bool is_left(long long int j, long long int i) {
    return i && node[i].left == j;
  }
  void up(long long int j) {
    if (!j) return;
    long long int l = node[j].left;
    long long int r = node[j].right;
    node[j].size = node[j].vir + 1;
    node[j].size2 = node[j].vir2;
    if (l) {
      node[j].size += node[l].size;
      node[j].size2 += node[l].size * node[l].size;
      node[l].parent = j;
    }
    if (r) {
      node[j].size += node[r].size;
      node[j].size2 += node[r].size * node[r].size;
      node[r].parent = j;
    }
  }
  void rotate(long long int j) {
    long long int p = node[j].parent;
    long long int pp = node[p].parent;
    assert(j);
    assert(p);
    node[j].parent = pp;
    if (nroot(p)) {
      is_left(p, pp) ? node[pp].left = j : node[pp].right = j;
    }
    if (is_left(j, p)) {
      node[p].left = node[j].right;
      node[j].right = p;
    } else {
      node[p].right = node[j].left;
      node[j].left = p;
    }
    up(p);
    up(j);
  }
  void Splay(long long int j) {
    assert(j);
    while (nroot(j)) {
      long long int p = node[j].parent;
      long long int pp = node[p].parent;
      if (nroot(p)) {
        if (is_left(j, p) ^ is_left(p, pp)) {
          rotate(j);
        } else
          rotate(p);
      }
      rotate(j);
    }
  }
  void access(long long int j) {
    long long int i = 0;
    while (j) {
      Splay(j);
      node[j].vir += node[node[j].right].size;
      node[j].vir2 += node[node[j].right].size * node[node[j].right].size;
      node[j].right = i;
      node[j].vir -= node[node[j].right].size;
      node[j].vir2 -= node[node[j].right].size * node[node[j].right].size;
      up(j);
      i = j;
      j = node[j].parent;
    }
  }
  long long int find_root(long long int j) {
    access(j);
    Splay(j);
    while (node[j].left) {
      j = node[j].left;
    }
    Splay(j);
    return j;
  }
  long long int get(long long int x) {
    if (!x) return 0;
    x = find_root(x);
    return node[x].size2;
  }
  void link(long long int j, long long int p) {
    ans -= get(p);
    ans -= get(j);
    access(j);
    Splay(j);
    assert(!node[j].left);
    node[j].parent = p;
    node[p].vir += node[j].size;
    node[p].vir2 += node[j].size * node[j].size;
    up(p);
    ans += get(j);
  }
  void cut(long long int j) {
    ans -= get(j);
    access(j);
    Splay(j);
    long long int l = node[j].left;
    node[l].parent = 0;
    node[j].left = 0;
    up(j);
    ans += get(l);
    ans += get(j);
  }
} LCT;
vector<long long int> adj[400005];
vector<long long int> val(400005);
vector<long long int> d(400005, 0);
vector<long long int> anc(400005, 0);
void dfs(long long int x, long long int pre) {
  for (auto y : adj[x]) {
    if (y == pre) continue;
    d[y] = d[x] + 1;
    dfs(y, x);
    anc[y] = x;
    node[y].key = d[y];
    LCT.link(y, x);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, q;
  cin >> n >> q;
  for (long long int i = 1; i <= n; i++) cin >> val[i];
  for (long long int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (long long int i = 1; i <= n + 1; i++) {
    node[i] = Node(0, i);
    LCT.up(i);
  }
  adj[n + 1].push_back(1);
  adj[1].push_back(n + 1);
  dfs(n + 1, 0);
  vector<long long int> delta(q + 1, 0);
  vector<pair<long long int, long long int> > Q[n + 1];
  delta[0] = ans * n;
  for (long long int i = 1; i <= n; i++) {
    Q[val[i]].push_back({0, i});
  }
  for (long long int i = 1; i <= q; i++) {
    long long int x, v;
    cin >> x >> v;
    Q[val[x]].push_back({-i, x});
    val[x] = v;
    Q[val[x]].push_back({i, x});
  }
  for (long long int i = 1; i <= n; i++) {
    set<long long int> now;
    for (auto p : Q[i]) {
      ans = 0;
      long long int t = p.first;
      long long int x = p.second;
      if (t >= 0) {
        now.insert(x);
        LCT.cut(x);
      } else {
        t = -t;
        now.erase(x);
        LCT.link(x, anc[x]);
      }
      delta[t] += ans;
    }
    for (auto p : now) {
      ans = 0;
      LCT.link(p, anc[p]);
    }
  }
  ans = n * n * n;
  for (long long int i = 0; i <= q; i++) {
    ans -= delta[i];
    cout << ans << "\n";
  }
}