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;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long globans;
struct LinkCutNode {
  int par, ch[2];
  int totcnt, midcnt;
  long long midans;
};
struct LinkCutTree {
  void updatepath(LinkCutNode &x, LinkCutNode *l, LinkCutNode *r) {
    x.totcnt = 1 + x.midcnt;
    if (l != nullptr) x.totcnt += l->totcnt;
    if (r != nullptr) x.totcnt += r->totcnt;
  }
  void removemiddle(LinkCutNode &x, LinkCutNode *y) {
    x.midcnt -= y->totcnt;
    x.midans -= (long long)y->totcnt * y->totcnt;
  }
  void addmiddle(LinkCutNode &x, LinkCutNode *y) {
    x.midcnt += y->totcnt;
    x.midans += (long long)y->totcnt * y->totcnt;
  }
  void removeglobal(LinkCutNode &x) {
    assert(x.par == -1 && x.ch[0] == -1);
    globans -= x.midans +
               (long long)(x.totcnt - x.midcnt - 1) * (x.totcnt - x.midcnt - 1);
  }
  void addglobal(LinkCutNode &x) {
    assert(x.par == -1 && x.ch[0] == -1);
    globans += x.midans +
               (long long)(x.totcnt - x.midcnt - 1) * (x.totcnt - x.midcnt - 1);
  }
  vector<LinkCutNode> nodes;
  void init(int n) {
    nodes = vector<LinkCutNode>(n);
    for (int x = (0); x < (((int)(nodes).size())); ++x) {
      nodes[x].par = nodes[x].ch[0] = nodes[x].ch[1] = -1;
    }
  }
  bool isroot(int x) {
    return nodes[x].par == -1 ||
           nodes[nodes[x].par].ch[0] != x && nodes[nodes[x].par].ch[1] != x;
  }
  int side(int x, int y) {
    return nodes[y].ch[0] == x ? 0 : nodes[y].ch[1] == x ? 1 : -1;
  }
  void updatepath(int x) {
    updatepath(nodes[x],
               nodes[x].ch[0] == -1 ? nullptr : &nodes[nodes[x].ch[0]],
               nodes[x].ch[1] == -1 ? nullptr : &nodes[nodes[x].ch[1]]);
  }
  void removemiddle(int x, int y) {
    if (y != -1) removemiddle(nodes[x], &nodes[y]);
  }
  void addmiddle(int x, int y) {
    if (y != -1) addmiddle(nodes[x], &nodes[y]);
  }
  void removeglobal(int x) { removeglobal(nodes[x]); }
  void addglobal(int x) { addglobal(nodes[x]); }
  void rotate(int x) {
    assert(!isroot(x));
    int y = nodes[x].par, z = nodes[y].par, k = side(x, y);
    assert(k == 0 || k == 1);
    assert(y != -1);
    nodes[x].par = z;
    if (!isroot(y)) nodes[z].ch[side(y, z)] = x;
    nodes[y].ch[k] = nodes[x].ch[1 - k];
    if (nodes[y].ch[k] != -1) nodes[nodes[y].ch[k]].par = y;
    nodes[x].ch[1 - k] = y, nodes[y].par = x;
    updatepath(y), updatepath(x);
  }
  void splay(int x) {
    while (!isroot(x)) {
      int y = nodes[x].par, z = nodes[y].par;
      if (!isroot(y)) rotate(side(x, y) != side(y, z) ? x : y);
      rotate(x);
    }
  }
  void access(int x) {
    for (int y = -1; x != -1; y = x, x = nodes[x].par) {
      splay(x);
      removemiddle(x, y);
      addmiddle(x, nodes[x].ch[1]);
      nodes[x].ch[1] = y;
      updatepath(x);
    }
  }
  int treetop(int x) {
    access(x);
    splay(x);
    while (nodes[x].ch[0] != -1) x = nodes[x].ch[0];
    splay(x);
    return x;
  }
  void link(int x, int y) {
    removeglobal(treetop(x)), removeglobal(treetop(y));
    splay(x);
    assert(nodes[x].par == -1 && nodes[x].ch[0] == -1);
    access(y);
    splay(y);
    assert(nodes[y].par == -1 && nodes[y].ch[1] == -1);
    nodes[x].ch[0] = y, nodes[y].par = x;
    updatepath(x);
    addglobal(treetop(x));
  }
  void cut(int x) {
    removeglobal(treetop(x));
    access(x);
    splay(x);
    assert(nodes[x].par == -1 && nodes[x].ch[0] != -1);
    int y = nodes[x].ch[0];
    nodes[y].par = -1;
    nodes[x].ch[0] = -1;
    updatepath(x);
    addglobal(treetop(x)), addglobal(treetop(y));
  }
};
const int MAXN = 400000;
const int MAXQ = 400000;
const int MAXCOL = MAXN;
int n, nq, ncol;
int initcol[MAXN];
vector<int> adj[MAXN];
int qidx[MAXQ], qcol[MAXQ];
long long ans[MAXQ + 1];
int par[MAXN];
LinkCutTree lct;
int ccol[MAXN];
vector<pair<int, pair<int, bool>>> when[MAXCOL];
void dfsinit(int at) {
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int to = adj[at][i];
    if (to == par[at]) continue;
    par[to] = at;
    dfsinit(to);
  }
}
void solve() {
  par[0] = -1;
  dfsinit(0);
  lct.init(n + 1);
  globans = 0;
  for (int i = (0); i < (n + 1); ++i)
    lct.nodes[i].midcnt = 0, lct.updatepath(i), lct.addglobal(i);
  for (int at = (0); at < (n); ++at) lct.link(at, par[at] == -1 ? n : par[at]);
  for (int i = (0); i < (ncol); ++i) when[i].clear();
  for (int i = (0); i < (n); ++i) {
    int ncol = initcol[i];
    ccol[i] = ncol;
    when[ncol].push_back(make_pair(0, make_pair(i, false)));
  }
  for (int i = (0); i < (nq); ++i) {
    int at = qidx[i], ocol = ccol[at], ncol = qcol[i];
    ccol[at] = ncol;
    if (ncol == ocol) continue;
    when[ocol].push_back(make_pair(i + 1, make_pair(at, true)));
    when[ncol].push_back(make_pair(i + 1, make_pair(at, false)));
  }
  for (int c = (0); c < (ncol); ++c) {
    sort(when[c].begin(), when[c].end());
    long long last = 0;
    for (int i = (0); i < (((int)(when[c]).size())); ++i) {
      int t = when[c][i].first, at = when[c][i].second.first;
      bool val = when[c][i].second.second;
      if (!val)
        lct.cut(at);
      else
        lct.link(at, par[at] == -1 ? n : par[at]);
      if (i + 1 >= ((int)(when[c]).size()) || when[c][i + 1].first > t) {
        long long cur = (long long)n * n - globans;
        ans[t] += cur - last;
        last = cur;
      }
    }
    for (int i = ((int)(when[c]).size()) - 1; i >= 0; --i) {
      int t = when[c][i].first, at = when[c][i].second.first;
      bool val = when[c][i].second.second;
      if (val)
        lct.cut(at);
      else
        lct.link(at, par[at] == -1 ? n : par[at]);
    }
  }
  for (int i = (0); i < (nq); ++i) ans[i + 1] += ans[i];
}
void run() {
  scanf("%d%d", &n, &nq);
  ncol = n;
  for (int i = (0); i < (n); ++i) scanf("%d", &initcol[i]), --initcol[i];
  for (int i = (0); i < (n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = (0); i < (nq); ++i)
    scanf("%d%d", &qidx[i], &qcol[i]), --qidx[i], --qcol[i];
  solve();
  for (int i = (0); i <= (nq); ++i) printf("%lld\n", ans[i]);
}
int main() {
  run();
  return 0;
}