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 ll = long long;
struct miao {
  int L1 = 0, R1 = 0, M1 = 0;
  ll L2 = 0, R2 = 0, M2 = 0;
  bool connected = true;
  miao(int L1_ = 0, int R1_ = 0, int M1_ = 0, ll L2_ = 0, ll R2_ = 0,
       ll M2_ = 0, bool connected_ = true)
      : L1(L1_),
        R1(R1_),
        M1(M1_),
        L2(L2_),
        R2(R2_),
        M2(M2_),
        connected(connected_) {}
};
miao operator-(miao a) {
  a.L1 *= -1;
  a.R1 *= -1;
  a.M1 *= -1;
  a.L2 *= -1;
  a.R2 *= -1;
  a.M2 *= -1;
  return a;
}
ll square(ll x) { return x * x; }
miao merge(miao a, miao b) {
  if (a.connected && b.connected) {
    return {a.L1 + b.L1, 0,           a.M1 + b.M1, square(a.L1 + b.L1),
            0,           a.M2 + b.M2, true};
  } else if (a.connected) {
    return {a.L1 + b.L1, b.R1,        a.M1 + b.M1, square(a.L1 + b.L1),
            b.R2,        a.M2 + b.M2, false};
  } else if (b.connected) {
    return {a.L1,        a.R1 + b.L1, a.M1 + b.M1, a.L2, square(a.R1 + b.L1),
            a.M2 + b.M2, false};
  } else {
    return {a.L1, b.R1, a.M1 + b.M1 + (a.R1 + b.L1),
            a.L2, b.R2, a.M2 + b.M2 + square(a.R1 + b.L1),
            false};
  }
}
struct segtree {
  int U = 0;
  vector<miao> dat;
  void build(int n) {
    U = 1;
    while (U < n) U *= 2;
    dat.resize(U * 2);
  }
  void setval(int k, miao v) { dat[k + U] = v; }
  void init() {
    for (int i = U - 1; i >= 1; i--) {
      dat[i] = merge(dat[i * 2], dat[i * 2 + 1]);
    }
  }
  void update(int k, miao v) {
    k += U;
    dat[k] = v;
    while (k > 1) {
      k >>= 1;
      dat[k] = merge(dat[k * 2], dat[k * 2 + 1]);
    }
  }
  miao query(int l, int r) {
    miao L, R;
    l += U;
    r += U;
    while (l <= r) {
      if ((l & 1) == 1) L = merge(L, dat[l++]);
      if ((r & 1) == 0) R = merge(dat[r--], R);
      l >>= 1;
      r >>= 1;
    }
    return merge(L, R);
  }
};
const int N = 400000;
vector<int> G[N];
int dashedL1[N];
long long dashedL2[N];
int dashedM1[N];
long long dashedM2[N];
int head[N];
int parent[N];
int sz[N];
int len[N];
bool removed[N];
segtree seg[N];
int sec;
int label[N];
void link(int u, miao v) {
  dashedL1[u] += v.L1;
  dashedM1[u] += v.M1 + v.R1;
  dashedL2[u] += v.L2;
  dashedM2[u] += v.M2 + v.R2;
}
miao single(int u) {
  miao v;
  if (removed[u]) {
    v.L1 = 0;
    v.R1 = 0;
    v.M1 = dashedL1[u] + dashedM1[u];
    v.L2 = 0;
    v.R2 = 0;
    v.M2 = dashedL2[u] + dashedM2[u];
    v.connected = false;
  } else {
    v.L1 = dashedL1[u] + 1;
    v.R1 = 0;
    v.M1 = dashedM1[u];
    v.L2 = square(dashedL1[u] + 1);
    v.R2 = 0;
    v.M2 = dashedM2[u];
    v.connected = true;
  }
  return v;
}
void update(int u) {
  int p = parent[head[u]];
  if (p != -1) {
    miao tmp = seg[head[u]].dat[1];
    link(p, -tmp);
  }
  seg[head[u]].update(label[u], single(u));
  if (p != -1) {
    miao tmp = seg[head[u]].dat[1];
    link(p, tmp);
    update(p);
  }
}
void dfs(int u, int p) {
  parent[u] = p;
  sz[u] = 1;
  for (int v : G[u]) {
    if (v == p) continue;
    dfs(v, u);
    sz[u] += sz[v];
  }
}
void dfs2(int u, int p) {
  pair<int, int> heavy(-1, -1);
  for (int v : G[u]) {
    if (v != p) {
      heavy = max(heavy, make_pair(sz[v], v));
    }
  }
  len[u] = 1;
  if (heavy.second != -1) {
    int v = heavy.second;
    label[v] = label[u] + 1;
    head[v] = head[u];
    dfs2(v, u);
    len[u] = len[v] + 1;
  }
  for (int v : G[u]) {
    if (v != p && v != heavy.second) {
      head[v] = v;
      dfs2(v, u);
      dashedL1[u] += sz[v];
      dashedL2[u] += (ll)sz[v] * sz[v];
    }
  }
  if (head[u] == u) {
    seg[u].build(len[u]);
  }
}
ostream &operator<<(ostream &o, miao v) {
  o << "(";
  o << "L1=" << v.L1 << ",";
  o << "R1=" << v.R1 << ",";
  o << "M1=" << v.M1 << ",";
  o << "L2=" << v.L2 << ",";
  o << "R2=" << v.R2 << ",";
  o << "M2=" << v.M2 << ",";
  o << "c=" << v.connected;
  o << ")";
  return o;
}
struct qtype {
  int time;
  int u;
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> color(n);
  vector<vector<qtype>> events(n);
  for (int i = 0; i < n; i++) {
    cin >> color[i];
    color[i]--;
    events[color[i]].push_back({0, i});
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0, -1);
  dfs2(0, -1);
  for (int i = 0; i < n; i++) {
    seg[head[i]].setval(label[i], single(i));
  }
  for (int i = 0; i < n; i++) {
    seg[i].init();
  }
  for (int i = 0; i < m; i++) {
    int u, x;
    cin >> u >> x;
    u--;
    x--;
    events[color[u]].push_back({i + 1, u});
    color[u] = x;
    events[color[u]].push_back({i + 1, u});
  }
  vector<ll> ans(m + 2);
  for (int i = 0; i < n; i++) {
    if (events[i].empty()) continue;
    int j = 0;
    while (j < events[i].size()) {
      int k = j;
      while (j < events[i].size() && events[i][j].time == events[i][k].time) {
        removed[events[i][j].u] ^= 1;
        update(events[i][j].u);
        j++;
      }
      int s = events[i][k].time;
      int t = j == events[i].size() ? m + 1 : events[i][j].time;
      miao tmp = seg[head[0]].dat[1];
      long long sum = tmp.L2 + tmp.R2 + tmp.M2;
      ans[s] += (ll)n * n - sum;
      ans[t] -= (ll)n * n - sum;
    }
    for (qtype q : events[i]) {
      removed[q.u] ^= 1;
      update(q.u);
    }
  }
  for (int i = 0; i <= m; i++) {
    ans[i + 1] += ans[i];
    cout << ans[i] << '\n';
  }
}