/*Coded by::
**Avinash Tiwary**
**BE/10298/2015**
**Production Engineer**
**Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define INF 1e18
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll n,block,ar[M5],st[M5],en[M5],dep[M5],con[M5],out[M5],par[M5][20],answer=0,timer=0,kha[M5];
struct query{
ll l,r,i,p;
}q[M5];
bool comp(query a,query b){
if(a.l/block!=b.l/block) return a.l<b.l;
return a.r<b.r;
}
vector<list<ll> >g(M5);
void dfs(ll cur,ll p){
dep[cur]=dep[p]+1;
par[cur][0]=p;
timer++;
st[cur]=timer;
kha[timer]=cur;
for(auto it=g[cur].begin();it!=g[cur].end();it++) if(*it!=p) dfs(*it,cur);
timer++;
en[cur]=timer;
kha[timer]=cur;
}
void preLCA(){
for(ll i=1;i<log2(n)+1;i++){
for(ll j=1;j<=n;j++){
if(par[j][i-1]!=-1)
par[j][i]=par[par[j][i-1]][i-1];
}
}
}
ll lca(ll u,ll v){
if(dep[u]>dep[v]) swap(u,v);
ll dif=dep[v]-dep[u];
while(dif>0){
ll up=log2(dif);
v=par[v][up];
dif-=(1<<up);
}
if(u==v) return u;
for(ll i=log2(n)+1;i>=0;i--) if(par[u][i]!=par[v][i]){u=par[u][i]; v=par[v][i];}
return par[u][0];
}
set<ll> ss;
void add(ll i){
con[i]++;
if(con[i]==1){
ss.insert(ar[i]);
}
if(con[i]==2){
ss.erase(ar[i]);
}
}
void remove(ll i){
con[i]--;
if(con[i]==1){
ss.insert(ar[i]);
}
if(con[i]==0){
ss.erase(ar[i]);
}
}
int main(){
//buf;
//sieve();
//fact();
ll l,r,i,j,test,ans,m,k,a,b; //string s;
//cin>>test;
test=1;
while(test--){
cin>>n>>m;
for(i=1;i<=n;i++) cin>>ar[i];
i=1;
while(i<n){
cin>>a>>b;
g[a].pb(b); g[b].pb(a);
i++;
}
memset(par,-1,sizeof(par));
dep[0]=-1; dfs(1,0);
//for(i=1;i<=n;i++) cout<<st[i]<<" "<<en[i]<<endl;
block=timer/sqrt(timer);
preLCA();
for(i=0;i<m;i++){
cin>>a>>b;
q[i].i=i;
ll l=lca(a,b);
if(st[a]>st[b]) swap(a,b);
if(l==a||l==b){
q[i].l=st[a]; q[i].r=st[b]; q[i].p=-1;
}
else{
q[i].l=en[a]; q[i].r=st[b]; q[i].p=l;
}
}
block=timer/sqrt(timer);
sort(q,q+m,comp);
ll cl=1,cr=1; add(1);
for(i=0;i<m;i++){
ll u=q[i].l,v=q[i].r;
while(cl<u){
remove(kha[cl]);
cl++;
}
while(cl>u){
add(kha[cl+1]);
cl--;
}
//cout<<endl;
while(cr>v){
remove(kha[cr]);
cr--;
}
while(cr<v){
add(kha[cr+1]);
cr++;
}
if(q[i].p!=-1&&con[ar[q[i].p]]==0) out[i]=ss.size()+1;
else out[i]=ss.size();
}
for(i=0;i<m;i++) cout<<out[i]<<" ";
}
return 0;
}
LypDb2RlZCBieTo6CiAgICAqKkF2aW5hc2ggVGl3YXJ5KioKICAgICoqQkUvMTAyOTgvMjAxNSoqCiAgICAqKlByb2R1Y3Rpb24gRW5naW5lZXIqKgogICAgKipQcm9kdWNpbmcgPGNvZGU+KioKKi8KI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBidWYgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyAoMCksIGNpbi50aWUgKDApCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIGRvdWJsZSBkb2I7CiNkZWZpbmUgTUFYIDUwMDEwCiNkZWZpbmUgTTUgMjAwMDA5CiNkZWZpbmUgTTYgMjAwMDAwOQojZGVmaW5lIE0gMTAwMDAwMDAwNwojZGVmaW5lIElORiAxZTE4CnVzaW5nIG5hbWVzcG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xXTsKICAgICAgICB9CiAgICB9Cn0KbGwgbGNhKGxsIHUsbGwgdil7CiAgICBpZihkZXBbdV0+ZGVwW3ZdKSBzd2FwKHUsdik7CiAgICBsbCBkaWY9ZGVwW3ZdLWRlcFt1XTsKICAgIHdoaWxlKGRpZj4wKXsKICAgICAgICBsbCB1cD1sb2cyKGRpZik7CiAgICAgICAgdj1wYXJbdl1bdXBdOwogICAgICAgIGRpZi09KDE8PHVwKTsKICAgIH0KICAgIGlmKHU9PXYpIHJldHVybiB1OwogICAgZm9yKGxsIGk9bG9nMihuKSsxO2k+PTA7aS0tKSBpZihwYXJbdV1baV0hPXBhclt2XVtpXSl7dT1wYXJbdV1baV07IHY9cGFyW3ZdW2ldO30KICAgIHJldHVybiBwYXJbdV1bMF07Cn0Kc2V0PGxsPiBzczsKdm9pZCBhZGQobGwgaSl7CiAgICBjb25baV0rKzsKICAgIGlmKGNvbltpXT09MSl7IAogICAgICAgIHNzLmluc2VydChhcltpXSk7CiAgICB9CiAgICBpZihjb25baV09PTIpeyAKICAgICAgICBzcy5lcmFzZShhcltpXSk7CiAgICB9Cn0Kdm9pZCByZW1vdmUobGwgaSl7CiAgICBjb25baV0tLTsKICAgIGlmKGNvbltpXT09MSl7IAogICAgICAgIHNzLmluc2VydChhcltpXSk7CiAgICB9CiAgICBpZihjb25baV09PTApeyAKICAgICAgICBzcy5lcmFzZShhcltpXSk7CiAgICB9Cn0KaW50IG1haW4oKXsKICAgIC8vYnVmOyAKICAgIC8vc2lldmUoKTsgCiAgICAvL2ZhY3QoKTsKICAgIGxsIGwscixpLGosdGVzdCxhbnMsbSxrLGEsYjsgLy9zdHJpbmcgczsKICAgIC8vY2luPj50ZXN0OwogICAgdGVzdD0xOwogICAgd2hpbGUodGVzdC0tKXsKICAgICAgICBjaW4+Pm4+Pm07CiAgICAgICAgZm9yKGk9MTtpPD1uO2krKykgY2luPj5hcltpXTsKICAgICAgICBpPTE7CiAgICAgICAgd2hpbGUoaTxuKXsKICAgICAgICAgICAgY2luPj5hPj5iOwogICAgICAgICAgICBnW2FdLnBiKGIpOyBnW2JdLnBiKGEpOwogICAgICAgICAgICBpKys7CiAgICAgICAgfQogICAgICAgIG1lbXNldChwYXIsLTEsc2l6ZW9mKHBhcikpOwogICAgICAgIGRlcFswXT0tMTsgZGZzKDEsMCk7CiAgICAgICAgLy9mb3IoaT0xO2k8PW47aSsrKSBjb3V0PDxzdFtpXTw8IiAiPDxlbltpXTw8ZW5kbDsKICAgICAgICBibG9jaz10aW1lci9zcXJ0KHRpbWVyKTsKICAgICAgICBwcmVMQ0EoKTsKICAgICAgICBmb3IoaT0wO2k8bTtpKyspewogICAgICAgICAgICBjaW4+PmE+PmI7CiAgICAgICAgICAgIHFbaV0uaT1pOwogICAgICAgICAgICBsbCBsPWxjYShhLGIpOwogICAgICAgICAgICBpZihzdFthXT5zdFtiXSkgc3dhcChhLGIpOwogICAgICAgICAgICBpZihsPT1hfHxsPT1iKXsKICAgICAgICAgICAgICAgIHFbaV0ubD1zdFthXTsgcVtpXS5yPXN0W2JdOyBxW2ldLnA9LTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIHFbaV0ubD1lblthXTsgcVtpXS5yPXN0W2JdOyBxW2ldLnA9bDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBibG9jaz10aW1lci9zcXJ0KHRpbWVyKTsKICAgICAgICBzb3J0KHEscSttLGNvbXApOwogICAgICAgIGxsIGNsPTEsY3I9MTsgYWRkKDEpOwogICAgICAgIGZvcihpPTA7aTxtO2krKyl7CiAgICAgICAgICAgIGxsIHU9cVtpXS5sLHY9cVtpXS5yOwogICAgICAgICAgICB3aGlsZShjbDx1KXsKICAgICAgICAgICAgICAgIHJlbW92ZShraGFbY2xdKTsKICAgICAgICAgICAgICAgIGNsKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUoY2w+dSl7CiAgICAgICAgICAgICAgICBhZGQoa2hhW2NsKzFdKTsKICAgICAgICAgICAgICAgIGNsLS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy9jb3V0PDxlbmRsOwogICAgICAgICAgICB3aGlsZShjcj52KXsKICAgICAgICAgICAgICAgIHJlbW92ZShraGFbY3JdKTsKICAgICAgICAgICAgICAgIGNyLS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUoY3I8dil7CiAgICAgICAgICAgICAgICBhZGQoa2hhW2NyKzFdKTsKICAgICAgICAgICAgICAgIGNyKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYocVtpXS5wIT0tMSYmY29uW2FyW3FbaV0ucF1dPT0wKSBvdXRbaV09c3Muc2l6ZSgpKzE7CiAgICAgICAgICAgIGVsc2Ugb3V0W2ldPXNzLnNpemUoKTsKICAgICAgICB9CiAgICAgICAgZm9yKGk9MDtpPG07aSsrKSBjb3V0PDxvdXRbaV08PCIgIjsKICAgIH0KICAgIHJldHVybiAwOwp9