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;
void read(int &x) {
  static char c;
  int f = 0;
  while (!isdigit(c = getchar()))
    if (c == '-') f = 1;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
  if (f) x = -x;
}
void read(long long &x) {
  static char c;
  int f = 0;
  while (!isdigit(c = getchar()))
    if (c == '-') f = 1;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
  if (f) x = -x;
}
void read(unsigned int &x) {
  static char c;
  while (!isdigit(c = getchar()))
    ;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
}
void read(unsigned long long &x) {
  static char c;
  while (!isdigit(c = getchar()))
    ;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
}
void chkmax(int &x, int y) {
  if (y > x) x = y;
}
void chkmin(int &x, int y) {
  if (y < x) x = y;
}
void chkmax(long long &x, long long y) {
  if (y > x) x = y;
}
void chkmin(long long &x, long long y) {
  if (y < x) x = y;
}
void chkmax(unsigned int &x, unsigned int y) {
  if (y > x) x = y;
}
void chkmin(unsigned int &x, unsigned int y) {
  if (y < x) x = y;
}
void chkmax(unsigned long long &x, unsigned long long y) {
  if (y > x) x = y;
}
void chkmin(unsigned long long &x, unsigned long long y) {
  if (y < x) x = y;
}
long long sq(long long x) { return x * x; }
const int N = 4e5 + 10;
int n, m;
vector<int> Edge[N];
int _Fat[N], col[N];
long long def[N], _def;
int cnt;
vector<pair<int, int> > O[N];
namespace LCT {
struct Node {
  int fat, son[2];
  long long alls, ligs, ligs2, alls2;
} t[N];
void Init() {
  for (int i = 1; i <= n + 1; ++i)
    t[i].fat = t[i].son[0] = t[i].son[1] = t[i].ligs = t[i].ligs2 = 0,
    t[i].alls = t[i].alls2 = 1;
}
void Update(int now) {
  int ls = t[now].son[0], rs = t[now].son[1];
  t[now].alls = t[ls].alls + t[rs].alls + t[now].ligs + 1;
  t[now].alls2 = sq(t[now].alls);
}
int NoRt(int now) {
  for (int D : {0, 1})
    if (t[t[now].fat].son[D] == now) return true;
  return false;
}
int GDir(int now) { return t[t[now].fat].son[1] == now; }
void Rorate(int now) {
  int Fat = t[now].fat, Gat = t[Fat].fat;
  int Fdir = GDir(now), Gdir = GDir(Fat);
  if (NoRt(Fat)) t[Gat].son[Gdir] = now;
  t[now].fat = Gat, t[Fat].fat = now;
  t[t[now].son[Fdir ^ 1]].fat = Fat;
  t[Fat].son[Fdir] = t[now].son[Fdir ^ 1];
  t[now].son[Fdir ^ 1] = Fat;
  Update(Fat), Update(now);
}
void Splay(int now) {
  while (NoRt(now)) {
    int Fat = t[now].fat;
    if (NoRt(Fat)) (GDir(now) ^ GDir(Fat)) ? Rorate(now) : Rorate(Fat);
    Rorate(now);
  }
}
void Access(int now) {
  for (int i = 0; now; now = t[i = now].fat) {
    int &rs = t[now].son[1];
    Splay(now);
    t[now].ligs -= t[i].alls, t[now].ligs2 -= t[i].alls2;
    t[now].ligs += t[rs].alls, t[now].ligs2 += t[rs].alls2;
    rs = i, Update(now);
  }
}
int Findroot(int now) {
  Access(now), Splay(now);
  while (t[now].son[0]) now = t[now].son[0];
  return Splay(now), now;
}
void Link(int now, long long &res) {
  Splay(now), res -= t[now].ligs2 + t[t[now].son[1]].alls2;
  int Fat = _Fat[now];
  int Rt = Findroot(Fat);
  Splay(Rt), res -= t[t[Rt].son[1]].alls2;
  Splay(Fat), t[now].fat = Fat;
  Update(now), t[Fat].ligs += t[now].alls, t[Fat].ligs2 += t[now].alls2,
      Update(Fat);
  Access(now), Splay(Rt), res += t[t[Rt].son[1]].alls2;
}
void Cut(int now, long long &res) {
  Access(now), res += t[now].ligs2;
  int Fat = _Fat[now];
  int Rt = Findroot(Fat);
  Access(now), Splay(Rt), res -= t[t[Rt].son[1]].alls2;
  Splay(now), t[now].son[0] = t[t[now].son[0]].fat = 0, Update(Fat);
  Splay(Rt), res += t[t[Rt].son[1]].alls2;
}
};  // namespace LCT
using namespace LCT;
void Modify(int now, long long &res) {
  if (t[now].fat)
    Cut(now, res);
  else
    Link(now, res);
}
void Work() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) {
    read(col[i]);
    O[col[i]].push_back(make_pair(i, 0));
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    read(u), read(v);
    Edge[u].push_back(v), Edge[v].push_back(u);
  }
  const auto &GetF = []() -> void {
    function<void(int, int)> dfs;
    dfs = [&dfs](int now, int fa) -> void {
      _Fat[now] = fa;
      for (int v : Edge[now])
        if (v != fa) dfs(v, now);
    };
    dfs(1, n + 1);
  };
  GetF();
  for (int i = 1; i <= m; ++i) {
    int u, c;
    read(u), read(c);
    O[col[u]].push_back(make_pair(u, i));
    O[col[u] = c].push_back(make_pair(u, i));
  }
  Init();
  for (int i = 1; i <= n; ++i) Modify(i, _def);
  for (int i = 1; i <= n; ++i) {
    if (!O[i].size()) continue;
    for (int o = 0; o < O[i].size(); ++o) {
      int now = O[i][o].first, tim = O[i][o].second;
      Modify(now, def[tim]);
    }
    for (int o = O[i].size() - 1; ~o; --o) {
      int now = O[i][o].first;
      Modify(now, _def);
    }
  }
  long long Ans = 0;
  for (int i = 0; i <= m; ++i) printf("%lld\n", Ans -= def[i]);
}
int main() { Work(); }