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;
template <class node>
struct link_cut_tree {
  bool connected(node* u, node* v) { return lca(u, v) != NULL; }
  int depth(node* u) {
    access(u);
    return get_sz(u->ch[0]);
  }
  node* get_root(node* u) {
    access(u);
    while (u->ch[0]) u = u->ch[0], u->push();
    return access(u), u;
  }
  node* ancestor(node* u, int k) {
    k = depth(u) - k;
    for (;; u->push()) {
      int sz = get_sz(u->ch[0]);
      if (sz == k) return access(u), u;
      if (sz < k)
        k -= sz + 1, u = u->ch[1];
      else
        u = u->ch[0];
    }
  }
  node* lca(node* u, node* v) {
    if (u == v) return u;
    access(u);
    access(v);
    if (!u->p) return NULL;
    u->splay();
    return u->p ?: u;
  }
  void link(node* u, node* v) {
    make_root(v);
    access(u);
    set_link(v, u, 0);
    v->update();
  }
  void cut(node* u) {
    access(u);
    u->ch[0]->p = NULL;
    u->ch[0] = NULL;
    u->update();
  }
  void cut(node* u, node* v) { cut(depth(u) > depth(v) ? u : v); }
  void make_root(node* u) {
    access(u);
    u->rev ^= 1;
    access(u);
  }
  void access(node* u) {
    for (node *v = u, *pre = NULL; v; v = v->p) {
      v->splay();
      if (pre) v->update_vsub(pre, false);
      if (v->ch[1]) v->update_vsub(v->ch[1], true);
      v->ch[1] = pre;
      v->update();
      pre = v;
    }
    u->splay();
  }
  node* operator[](int i) { return &data[i]; }
  int operator[](node* i) { return i - &data[0]; }
  vector<node> data;
  link_cut_tree(int n) : data(n) {}
};
template <typename pnode>
struct splay_tree {
  pnode ch[2], p;
  bool rev;
  int sz;
  splay_tree() {
    ch[0] = ch[1] = p = NULL;
    rev = 0;
    sz = 1;
  }
  friend int get_sz(pnode u) { return u ? u->sz : 0; }
  virtual void update() {
    if (ch[0]) ch[0]->push();
    if (ch[1]) ch[1]->push();
    sz = 1 + get_sz(ch[0]) + get_sz(ch[1]);
  }
  virtual void push() {
    if (rev) {
      if (ch[0]) ch[0]->rev ^= 1;
      if (ch[1]) ch[1]->rev ^= 1;
      swap(ch[0], ch[1]);
      rev = 0;
    }
  }
  int dir() {
    if (!p) return -2;
    if (p->ch[0] == this) return 0;
    if (p->ch[1] == this) return 1;
    return -1;
  }
  bool is_root() { return dir() < 0; }
  friend void set_link(pnode u, pnode v, int d) {
    if (v) v->p = u;
    if (d >= 0) u->ch[d] = v;
  }
  void rotate() {
    int x = dir();
    pnode g = p;
    set_link(g->p, static_cast<pnode>(this), g->dir());
    set_link(g, ch[x ^ 1], x);
    set_link(static_cast<pnode>(this), g, x ^ 1);
    g->update();
  }
  void splay() {
    while (!is_root() && !p->is_root()) {
      p->p->push(), p->push(), push();
      dir() == p->dir() ? p->rotate() : rotate();
      rotate();
    }
    if (!is_root()) p->push(), push(), rotate();
    push(), update();
  }
};
struct node : splay_tree<node*> {
  using splay_tree::ch;
  int rsz, vrsz;
  long long chsz2, vchsz2;
  node() : splay_tree() {
    rsz = 1;
    vrsz = chsz2 = vchsz2 = 0;
  }
  void update() override {
    splay_tree::update();
    rsz = 1 + (ch[0] ? ch[0]->rsz : 0) + (ch[1] ? ch[1]->rsz : 0) + vrsz;
    chsz2 = (ch[0] ? ((long long)ch[0]->rsz * ch[0]->rsz) : 0) +
            (ch[1] ? ((long long)ch[1]->rsz * ch[1]->rsz) : 0) + vchsz2;
  }
  void update_vsub(node* v, bool add) {
    vrsz += (add ? +1 : -1) * v->rsz;
    vchsz2 += (add ? +1 : -1) * (long long)v->rsz * v->rsz;
  }
  void push() override { splay_tree::push(); }
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> col(n);
  vector<vector<pair<int, int>>> e(n);
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    --x;
    e[x].push_back({0, i});
    col[i] = x;
  }
  vector<vector<int>> adj(n + 1);
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  adj[n].push_back(0);
  link_cut_tree<node> lct(n + 1);
  vector<int> parent(n + 1, -1);
  function<void(int)> dfs = [&](int u) {
    for (auto v : adj[u])
      if (v != parent[u]) {
        lct.link(lct[u], lct[v]);
        parent[v] = u;
        dfs(v);
      }
  };
  dfs(n);
  for (int i = 1, u, x; i <= q; ++i) {
    cin >> u >> x;
    --u, --x;
    if (col[u] == x) continue;
    e[col[u]].push_back({i, ~u});
    e[x].push_back({i, u});
    col[u] = x;
  }
  vector<long long> ans(q + 1);
  vector<bool> nodes(n);
  for (auto& c : e) {
    long long last = 0, sz2 = (long long)n * n;
    for (auto& i : c) {
      int ru = max(i.second, ~i.second);
      auto u = lct[ru], pu = lct[parent[ru]], r = lct.get_root(pu);
      if (i.second < 0) {
        nodes[ru] = false;
        sz2 -= r->chsz2;
        lct.access(u);
        sz2 -= u->chsz2;
        lct.link(pu, u);
        lct.access(r);
        sz2 += r->chsz2;
      } else {
        nodes[ru] = true;
        sz2 -= r->chsz2;
        lct.cut(u);
        sz2 += u->chsz2;
        lct.access(r);
        sz2 += r->chsz2;
      }
      if (i.first > 0 || &i == &c.back() || c[&i - &c[0] + 1].first > 0) {
        ans[i.first] += -last;
        ans[i.first] += (last = (long long)n * n - sz2);
      }
    }
    for (auto& i : c) {
      int ru = max(i.second, ~i.second);
      if (nodes[ru]) {
        nodes[ru] = false;
        lct.link(lct[parent[ru]], lct[ru]);
      }
    }
  }
  partial_sum(ans.begin(), ans.end(), ans.begin());
  for (auto& i : ans) cout << i << "\n";
  return 0;
}