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;
    assert(k >= 0);
    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];
    }
    assert(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) {
    assert(!connected(u, 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);
    assert(!u->ch[0] && !u->ch[1]);
  }
  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();
    assert(!u->ch[1]);
  }
  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() {
    assert(!is_root());
    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();
    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();
  }
};
struct node : splay_tree<node*> {
  using splay_tree::ch;
  bool col;
  long long sz2, szwup, szwdown, vsz2, vszwup, vszwup2;
  node() : splay_tree() {
    col = 0;
    szwup = 1;
    szwdown = -1;
    sz2 = vsz2 = vszwup = vszwup2 = 0;
  }
  void update() override {
    splay_tree::update();
    sz2 = vsz2;
    szwup = !col;
    szwdown = -szwup;
    if (ch[0]) {
      szwup = ch[0]->szwup;
      if (ch[0]->szwdown < 0) {
        szwup += !col;
      } else {
        szwdown = ch[0]->szwdown;
        if (col)
          sz2 += szwdown * szwdown, szwdown = 0;
        else
          ++szwdown;
      }
      sz2 += ch[0]->sz2;
    }
    if (col)
      sz2 += vszwup2;
    else {
      if (szwdown < 0)
        szwup += vszwup;
      else
        szwdown += vszwup;
    }
    if (ch[1]) {
      if (szwdown < 0 && ch[1]->szwdown < 0)
        szwup += ch[1]->szwup;
      else if (szwdown < 0)
        szwup += ch[1]->szwup, szwdown = ch[1]->szwdown;
      else if (ch[1]->szwdown < 0)
        szwdown += ch[1]->szwup;
      else
        sz2 += (szwdown + ch[1]->szwup) * (szwdown + ch[1]->szwup),
            szwdown = ch[1]->szwdown;
      sz2 += ch[1]->sz2;
    }
  }
  void update_vsub(node* v, bool add) {
    const int sg = add ? +1 : -1;
    vsz2 += sg * (v->sz2 + (v->szwdown > 0) * v->szwdown * v->szwdown);
    vszwup += sg * v->szwup;
    vszwup2 += sg * v->szwup * v->szwup;
  }
  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;
  }
  link_cut_tree<node> lct(n + 1);
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    --u, --v;
    lct.link(lct[u], lct[v]);
  }
  lct.link(lct[n], lct[0]);
  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;
  }
  auto root = lct[n];
  lct.access(root);
  root->col = true;
  root->update();
  vector<long long> ans(q + 1);
  vector<bool> nodes(n);
  for (auto& c : e) {
    long long last = 0;
    for (auto& i : c) {
      int ru = max(i.second, ~i.second);
      auto u = lct[ru];
      lct.access(u);
      u->col = i.second >= 0;
      u->update();
      nodes[ru] = u->col;
      if (i.first > 0 || &i == &c.back() || c[&i - &c[0] + 1].first > 0) {
        ans[i.first] += -last;
        lct.access(root);
        ans[i.first] += (last = (long long)n * n -
                                (root->sz2 + root->szwdown * root->szwdown));
      }
    }
    for (auto& i : c) {
      int ru = max(i.second, ~i.second);
      if (nodes[ru]) {
        nodes[ru] = false;
        auto u = lct[ru];
        lct.access(u);
        u->col = false;
        u->update();
      }
    }
  }
  partial_sum(ans.begin(), ans.end(), ans.begin());
  for (auto& i : ans) cout << i << "\n";
  return 0;
}