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;
using Int = long long;
template <typename A>
struct LinkCutTree {
  struct Node {
    Node *l, *r, *p;
    int idx;
    bool rev;
    A val, dat, sum;
    Node() {}
    Node(int idx, A val, A dat, A sum)
        : idx(idx), rev(0), val(val), dat(dat), sum(sum) {
      l = r = p = nullptr;
    }
    bool is_root() { return !p || (p->l != this && p->r != this); }
  };
  A ai;
  const size_t LIM = 1e6 + 10;
  vector<Node> pool;
  size_t ptr;
  LinkCutTree() : ai(A()), pool(LIM), ptr(0) {}
  inline Node *create() { return &pool[ptr++]; }
  inline Node *create(int idx, A val) {
    return &(pool[ptr++] = Node(idx, val, ai, val));
  }
  void toggle(Node *t) {
    swap(t->l, t->r);
    t->rev ^= 1;
  }
  void eval(Node *t) {
    if (t->rev) {
      if (t->l) toggle(t->l);
      if (t->r) toggle(t->r);
      t->rev = false;
    }
  }
  inline A resolve(Node *t) { return t ? t->sum : ai; }
  inline void pushup(Node *t) {
    if (t == nullptr) return;
    t->sum = t->val + t->dat;
    t->sum += resolve(t->l);
    t->sum += resolve(t->r);
  }
  void rotR(Node *t) {
    Node *x = t->p, *y = x->p;
    if ((x->l = t->r)) t->r->p = x;
    t->r = x;
    x->p = t;
    if ((t->p = y)) {
      if (y->l == x) y->l = t;
      if (y->r == x) y->r = t;
    }
    pushup(x);
    pushup(t);
    pushup(y);
  }
  void rotL(Node *t) {
    Node *x = t->p, *y = x->p;
    if ((x->r = t->l)) t->l->p = x;
    t->l = x;
    x->p = t;
    if ((t->p = y)) {
      if (y->l == x) y->l = t;
      if (y->r == x) y->r = t;
    }
    pushup(x);
    pushup(t);
    pushup(y);
  }
  void splay(Node *t) {
    eval(t);
    while (!t->is_root()) {
      Node *q = t->p;
      if (q->is_root()) {
        eval(q);
        eval(t);
        if (q->l == t)
          rotR(t);
        else
          rotL(t);
      } else {
        auto *r = q->p;
        eval(r);
        eval(q);
        eval(t);
        if (r->l == q) {
          if (q->l == t)
            rotR(q), rotR(t);
          else
            rotL(t), rotR(t);
        } else {
          if (q->r == t)
            rotL(q), rotL(t);
          else
            rotR(t), rotL(t);
        }
      }
    }
  }
  Node *expose(Node *t) {
    Node *rp = nullptr;
    for (Node *c = t; c; c = c->p) {
      splay(c);
      c->dat += resolve(c->r);
      c->r = rp;
      c->dat -= resolve(c->r);
      pushup(c);
      rp = c;
    }
    splay(t);
    return rp;
  }
  void link(Node *par, Node *c) {
    expose(c);
    expose(par);
    c->p = par;
    par->r = c;
    pushup(par);
  }
  void cut(Node *c) {
    expose(c);
    Node *par = c->l;
    c->l = nullptr;
    pushup(c);
    par->p = nullptr;
  }
  void evert(Node *t) {
    expose(t);
    toggle(t);
    eval(t);
  }
  Node *root(Node *t) {
    expose(t);
    while (t->l) t = t->l;
    splay(t);
    return t;
  }
  bool is_connected(Node *a, Node *b) { return root(a) == root(b); }
  Node *lca(Node *a, Node *b) {
    expose(a);
    return expose(b);
  }
  A query(Node *t) {
    expose(t);
    return t->sum;
  }
};
template <typename T>
struct BIT {
  int n;
  vector<T> bit;
  BIT() : n(-1) {}
  BIT(int n_, T d) : n(n_), bit(n_ + 1, d) {}
  T sum(int i) {
    T s = bit[0];
    for (int x = i; x > 0; x -= (x & -x)) s += bit[x];
    return s;
  }
  void add(int i, T a) {
    if (i == 0) return;
    for (int x = i; x <= n; x += (x & -x)) bit[x] += a;
  }
};
signed CFR564_E() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> modv(n), modt(n);
  vector<int> cs(n);
  for (int i = 0; i < n; i++) {
    cin >> cs[i];
    cs[i]--;
    modv[cs[i]].emplace_back(i);
    modt[cs[i]].emplace_back(0);
  }
  vector<vector<int>> G(n + 1);
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  G[n].emplace_back(0);
  for (int i = 1; i <= m; i++) {
    int v, x;
    cin >> v >> x;
    v--;
    x--;
    modv[cs[v]].emplace_back(v);
    modt[cs[v]].emplace_back(i);
    cs[v] = x;
    modv[cs[v]].emplace_back(v);
    modt[cs[v]].emplace_back(i);
  }
  using ll = long long;
  struct A {
    ll sz1, sz2;
    A() : sz1(0), sz2() {}
    A(ll sz1, ll sz2) : sz1(sz1), sz2(sz2) {}
    A operator+(const A &a) const { return A(sz1 + a.sz1, sz2 + a.sz2); };
    A &operator+=(const A &a) {
      sz1 += a.sz1;
      sz2 += a.sz1 * a.sz1;
      return (*this);
    }
    A &operator-=(const A &a) {
      sz1 -= a.sz1;
      sz2 -= a.sz1 * a.sz1;
      return (*this);
    }
  };
  using LCT = LinkCutTree<A>;
  LCT lct;
  vector<LCT::Node *> vs(n + 1);
  for (int i = 0; i < (int)vs.size(); i++) vs[i] = lct.create(i, A(1, 0));
  vector<int> par(n + 1, 0);
  {
    using P = pair<int, int>;
    queue<P> q;
    q.emplace(n, -1);
    while (!q.empty()) {
      int v, p;
      tie(v, p) = q.front();
      q.pop();
      par[v] = p;
      if (~p) lct.link(vs[p], vs[v]);
      for (int u : G[v])
        if (u != p) q.emplace(u, v);
    }
  }
  vector<ll> delta(m + 1, 0);
  vector<int> color(n + 1, 0);
  int cnt = 0;
  for (int c = 0; c < n; c++) {
    ll lst = (ll)n * n, cur = (ll)n * n;
    delta[0] += lst;
    {
      auto rt = lct.root(vs[c]);
      lct.evert(vs[c]);
      lct.evert(rt);
      if (vs[c] != rt) cnt++;
    }
    if (modv[c].empty()) continue;
    for (int i = 0; i < (int)modv[c].size(); i++) {
      int v = modv[c][i];
      color[v] ^= 1;
      if (color[v]) {
        cur -= lct.query(lct.root(vs[v])).sz2;
        lct.cut(vs[v]);
        cur += lct.query(lct.root(vs[par[v]])).sz2;
        cur += lct.query(vs[v]).sz2;
      } else {
        cur -= lct.query(lct.root(vs[par[v]])).sz2;
        cur -= lct.query(vs[v]).sz2;
        lct.link(vs[par[v]], vs[v]);
        cur += lct.query(lct.root(vs[v])).sz2;
      }
      if (i + 1 == (int)modv[c].size() || modt[c][i] != modt[c][i + 1]) {
        delta[modt[c][i]] += cur - lst;
        lst = cur;
      }
    }
    for (int i = 0; i < (int)modv[c].size(); i++) {
      int v = modv[c][i];
      if (!color[v]) continue;
      color[v] ^= 1;
      lct.link(vs[par[v]], vs[v]);
    }
  }
  cerr << cnt << endl;
  ll ans = (ll)n * n * n;
  for (int i = 0; i <= m; i++) {
    ans -= delta[i];
    cout << ans << "\n";
  }
  cout << flush;
  return 0;
}
signed main() {
  CFR564_E();
  return 0;
}