#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define mp make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pii pair<int ,int >
#define all(v) v.begin(),v.end()
#define test(t) int t;cin>>t;while(t--)
ll poww(ll x,ll y) {ll res=1;x%=mod; assert(y>=0); for(;y;y>>=1){if(y&1)res=res*x%mod;x=x*x%mod;}return res;}
using namespace std;
struct query{
int l,r,k,idx;
}qu[100005];
int cnt[40005],freq[40005],bsize;
int P[40005][20],n,p[40005];
int a[40005],in[40005],out[40005];
vector<pair<ll,int> > b;
vector<int> v[40005],vv;
bool vis[40005];
int t,Lvl[40005],anss[100005];
int cmp(query lhs,query rhs){
if(lhs.l/bsize==rhs.l/bsize)
return lhs.r<rhs.r;
return lhs.l/bsize < rhs.l/bsize;
}
void dfs(int x,int lvl){
Lvl[x]=lvl;
vv.pb(x);
for(int i=0;i<v[x].size();++i)
if(!vis[v[x][i]]){
vis[v[x][i]]=1;
dfs(v[x][i],lvl+1);
p[v[x][i]]=x;
}
vv.pb(x);
}
void build(){
memset(P,-1,sizeof P);
memset(in,-1,sizeof in);
p[1]=-1;
int i,j;
for(i=1;i<=n;++i)
P[i][0]=p[i];
for(i=1;i<=n;++i)
for(j=1;j<=18;++j){
if(P[i][j-1]!=-1){
P[i][j]=P[P[i][j-1]][j-1];
}
}
}
int LCA(int x,int y){
int i;
if(Lvl[x]<Lvl[y])
swap(x,y);
int raise,dist=Lvl[x]-Lvl[y];
while(dist>0){
raise=log2(dist);
x=P[x][raise];
dist-=(1<<raise);
}
if(x==y)
return x;
for(i=16;i>=0;--i){
if(P[x][i]!=P[y][i]&&P[x][i]!=-1){
x=P[x][i];
y=P[y][i];
}
}
return p[x];
}
int main()
{
int i,j,q,l,r,ml,mr,c=1,y;
ll x;
scanf("%d",&n);
scanf("%d",&q);
bsize=sqrt(n);
for(i=1;i<=n;i++){
scanf("%lld",&x);
b.pb(mp(x,i));
}
sort(all(b));
a[b[0].second]=c;
for(i=1;i<n;++i){
if(b[i].first!=b[i-1].first)
c++;
a[b[i].second]=c;
}
for(i=0;i<n-1;++i){
scanf("%d %d",&x,&y);
v[x].pb(y);
v[y].pb(x);
}
vis[1]=1;
dfs(1,0);
build();
for(i=0;i<vv.size();++i){
if(in[vv[i]]==-1)
in[vv[i]]=i;
out[vv[i]]=i;
}
for(i=0;i<q;i++){
scanf("%d %d",&qu[i].l,&qu[i].r);
qu[i].idx=i;
qu[i].l;
qu[i].r;
}
ml=0;
mr=-1;
int lca;
for(i=0;i<q;i++){
l=qu[i].l;
r=qu[i].r;
if(in[l]>in[r])
swap(l,r);
lca=LCA(l,r);
if(lca==l){
qu[i].l=in[l];
qu[i].r=in[r];
qu[i].k=-1;
}
else{
qu[i].l=out[l];
qu[i].r=in[r];
qu[i].k=lca;
}
}
sort(qu,qu+q,cmp);
int ans=0;
for(i=0;i<q;++i){
l=qu[i].l;
r=qu[i].r;
while(mr<r){
mr++;
cnt[vv[mr]]++;
if(cnt[vv[mr]]==1){
if(freq[a[vv[mr]]]==0)
ans++;
freq[a[vv[mr]]]++;
}
if(cnt[vv[mr]]==2){
if(freq[a[vv[mr]]]==1)
ans--;
freq[a[vv[mr]]]--;
}
}
while(ml>l){
ml--;
cnt[vv[ml]]++;
if(cnt[vv[ml]]==1){
if(freq[a[vv[ml]]]==0)
ans++;
freq[a[vv[ml]]]++;
}
if(cnt[vv[ml]]==2){
if(freq[a[vv[ml]]]==1)
ans--;
freq[a[vv[ml]]]--;
}
}
while(ml<l){
cnt[vv[ml]]--;
if(cnt[vv[ml]]==0){
if(freq[a[vv[ml]]]==1)
ans--;
freq[a[vv[ml]]]--;
}
if(cnt[vv[ml]]==1){
if(freq[a[vv[ml]]]==0)
ans++;
freq[a[vv[ml]]]++;
}
ml++;
}
while(mr>r){
cnt[vv[mr]]--;
if(cnt[vv[mr]]==0){
if(freq[a[vv[mr]]]==1)
ans--;
freq[a[vv[mr]]]--;
}
if(cnt[vv[mr]]==1){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L2JzaXplPT1yaHMubC9ic2l6ZSkKICAgICAgICByZXR1cm4gbGhzLnI8cmhzLnI7CiAgICByZXR1cm4gbGhzLmwvYnNpemUgPCByaHMubC9ic2l6ZTsKfQoKdm9pZCBkZnMoaW50IHgsaW50IGx2bCl7CgogICAgTHZsW3hdPWx2bDsKICAgIHZ2LnBiKHgpOwogICAgZm9yKGludCBpPTA7aTx2W3hdLnNpemUoKTsrK2kpCiAgICBpZighdmlzW3ZbeF1baV1dKXsKICAgICAgICB2aXNbdlt4XVtpXV09MTsKICAgICAgICBkZnModlt4XVtpXSxsdmwrMSk7CiAgICAgICAgcFt2W3hdW2ldXT14OwogICAgfQogICAgdnYucGIoeCk7CiAgICAKfQoKCnZvaWQgYnVpbGQoKXsKCiAgICBtZW1zZXQoUCwtMSxzaXplb2YgUCk7CiAgICBtZW1zZXQoaW4sLTEsc2l6ZW9mIGluKTsKICAgIHBbMV09LTE7CiAgICBpbnQgaSxqOwogICAgZm9yKGk9MTtpPD1uOysraSkKICAgICAgICBQW2ldWzBdPXBbaV07CiAgICBmb3IoaT0xO2k8PW47KytpKQogICAgICAgIGZvcihqPTE7ajw9MTg7KytqKXsKICAgICAgICBpZihQW2ldW2otMV0hPS0xKXsKICAgICAgICAgICAgUFtpXVtqXT1QW1BbaV1bai0xXV1bai0xXTsKICAgICAgICB9CiAgICB9Cn0KCmludCBMQ0EoaW50IHgsaW50IHkpewoKICAgIGludCBpOwogICAgaWYoTHZsW3hdPEx2bFt5XSkKICAgICAgICBzd2FwKHgseSk7CiAgICBpbnQgcmFpc2UsZGlzdD1MdmxbeF0tTHZsW3ldOwogICAgd2hpbGUoZGlzdD4wKXsKICAgICAgICByYWlzZT1sb2cyKGRpc3QpOwogICAgICAgIHg9UFt4XVtyYWlzZV07CiAgICAgICAgZGlzdC09KDE8PHJhaXNlKTsKICAgIH0KICAgIGlmKHg9PXkpCiAgICAgICAgcmV0dXJuIHg7CiAgICBmb3IoaT0xNjtpPj0wOy0taSl7CiAgICAgICAgaWYoUFt4XVtpXSE9UFt5XVtpXSYmUFt4XVtpXSE9LTEpewogICAgICAgICAgICB4PVBbeF1baV07CiAgICAgICAgICAgIHk9UFt5XVtpXTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gcFt4XTsKCn0KCmludCBtYWluKCkKewogICAgaW50IGksaixxLGwscixtbCxtcixjPTEseTsKICAgIGxsIHg7CiAgICBzY2FuZigiJWQiLCZuKTsKICAgIHNjYW5mKCIlZCIsJnEpOwogICAgYnNpemU9c3FydChuKTsKICAgIGZvcihpPTE7aTw9bjtpKyspewogICAgICAgIHNjYW5mKCIlbGxkIiwmeCk7CiAgICAgICAgYi5wYihtcCh4LGkpKTsKICAgIH0KICAgIHNvcnQoYWxsKGIpKTsKICAgIGFbYlswXS5zZWNvbmRdPWM7CiAgICBmb3IoaT0xO2k8bjsrK2kpewogICAgICAgIGlmKGJbaV0uZmlyc3QhPWJbaS0xXS5maXJzdCkKICAgICAgICAgICAgYysrOwogICAgICAgIGFbYltpXS5zZWNvbmRdPWM7CiAgICB9CgogICAgZm9yKGk9MDtpPG4tMTsrK2kpewoKICAgICAgICBzY2FuZigiJWQgJWQiLCZ4LCZ5KTsKICAgICAgICB2W3hdLnBiKHkpOwogICAgICAgIHZbeV0ucGIoeCk7CiAgICB9CiAgICB2aXNbMV09MTsKICAgIGRmcygxLDApOwogICAgYnVpbGQoKTsKICAgIGZvcihpPTA7aTx2di5zaXplKCk7KytpKXsKICAgICAgICBpZihpblt2dltpXV09PS0xKQogICAgICAgICAgICBpblt2dltpXV09aTsKICAgICAgICBvdXRbdnZbaV1dPWk7CiAgICB9CiAgICBmb3IoaT0wO2k8cTtpKyspewogICAgICAgIHNjYW5mKCIlZCAlZCIsJnF1W2ldLmwsJnF1W2ldLnIpOwogICAgICAgIHF1W2ldLmlkeD1pOwogICAgICAgIHF1W2ldLmw7CiAgICAgICAgcXVbaV0ucjsKICAgIH0KICAgIG1sPTA7CiAgICBtcj0tMTsKICAgIGludCBsY2E7CiAgICBmb3IoaT0wO2k8cTtpKyspewogICAgICAgIGw9cXVbaV0ubDsKICAgICAgICByPXF1W2ldLnI7CiAgICAgICAgaWYoaW5bbF0+aW5bcl0pCiAgICAgICAgICAgIHN3YXAobCxyKTsKICAgICAgICBsY2E9TENBKGwscik7CiAgICAgICAgaWYobGNhPT1sKXsKICAgICAgICAgICAgcXVbaV0ubD1pbltsXTsKICAgICAgICAgICAgcXVbaV0ucj1pbltyXTsKICAgICAgICAgICAgcXVbaV0uaz0tMTsKICAgICAgICB9CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgcXVbaV0ubD1vdXRbbF07CiAgICAgICAgICAgIHF1W2ldLnI9aW5bcl07CiAgICAgICAgICAgIHF1W2ldLms9bGNhOwogICAgICAgIH0KICAgIH0KICAgIHNvcnQocXUscXUrcSxjbXApOwogICAgaW50IGFucz0wOwogICAgZm9yKGk9MDtpPHE7KytpKXsKICAgICAgICBsPXF1W2ldLmw7CiAgICAgICAgcj1xdVtpXS5yOwoKICAgICAgICB3aGlsZShtcjxyKXsKICAgICAgICAgICAgbXIrKzsKICAgICAgICAgICAgY250W3Z2W21yXV0rKzsKICAgICAgICAgICAgaWYoY250W3Z2W21yXV09PTEpewogICAgICAgICAgICAgICAgaWYoZnJlcVthW3Z2W21yXV1dPT0wKQogICAgICAgICAgICAgICAgICAgIGFucysrOwogICAgICAgICAgICAgICAgZnJlcVthW3Z2W21yXV1dKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoY250W3Z2W21yXV09PTIpewogICAgICAgICAgICAgICAgaWYoZnJlcVthW3Z2W21yXV1dPT0xKQogICAgICAgICAgICAgICAgICAgIGFucy0tOwogICAgICAgICAgICAgICAgZnJlcVthW3Z2W21yXV1dLS07CiAgICAgICAgICAgIH0KCiAgICAgICAgfQogICAgICAgIHdoaWxlKG1sPmwpewogICAgICAgICAgICBtbC0tOwoKICAgICAgICAgICAgY250W3Z2W21sXV0rKzsKICAgICAgICAgICAgaWYoY250W3Z2W21sXV09PTEpewogICAgICAgICAgICAgICAgaWYoZnJlcVthW3Z2W21sXV1dPT0wKQogICAgICAgICAgICAgICAgYW5zKys7CiAgICAgICAgICAgICAgICBmcmVxW2FbdnZbbWxdXV0rKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZihjbnRbdnZbbWxdXT09Mil7CiAgICAgICAgICAgICAgICBpZihmcmVxW2FbdnZbbWxdXV09PTEpCiAgICAgICAgICAgICAgICBhbnMtLTsKICAgICAgICAgICAgICAgIGZyZXFbYVt2dlttbF1dXS0tOwogICAgICAgICAgICB9CgogICAgICAgIH0KICAgICAgICB3aGlsZShtbDxsKXsKCiAgICAgICAgICAgIGNudFt2dlttbF1dLS07CiAgICAgICAgICAgIGlmKGNudFt2dlttbF1dPT0wKXsKICAgICAgICAgICAgICAgIGlmKGZyZXFbYVt2dlttbF1dXT09MSkKICAgICAgICAgICAgICAgICAgICBhbnMtLTsKICAgICAgICAgICAgICAgIGZyZXFbYVt2dlttbF1dXS0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKGNudFt2dlttbF1dPT0xKXsKICAgICAgICAgICAgICAgIGlmKGZyZXFbYVt2dlttbF1dXT09MCkKICAgICAgICAgICAgICAgICAgICBhbnMrKzsKICAgICAgICAgICAgICAgIGZyZXFbYVt2dlttbF1dXSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG1sKys7CgogICAgICAgIH0KICAgICAgICB3aGlsZShtcj5yKXsKCiAgICAgICAgICAgIGNudFt2dlttcl1dLS07CiAgICAgICAgICAgIGlmKGNudFt2dlttcl1dPT0wKXsKICAgICAgICAgICAgICAgIGlmKGZyZXFbYVt2dlttcl1dXT09MSkKICAgICAgICAgICAgICAgICAgICBhbnMtLTsKICAgICAgICAgICAgICAgIGZyZXFbYVt2dlttcl1dXS0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKGNudFt2dlttcl1dPT0xKXsKICAgICAgICAgICAgICAgIGlmKGZyZXFbYVt2dlttcl1dXT09MCkKICAgICAgICAgICAgICAgICAgICBhbnMrKzsKICAgICAgICAgICAgICAgIGZyZXFbYVt2dlttcl1dXSsrOwogICAgICAgICAgICB9CgogICAgICAgICAgICBtci0tOwogICAgICAgIH0KICAgICAgICBhbnNzW3F1W2ldLmlkeF09YW5zOwogICAgICAgIGlmKHF1W2ldLmshPS0xJiZmcmVxW2FbcXVbaV0ua11dPT0wKQogICAgICAgICAgICBhbnNzW3F1W2ldLmlkeF0rKzsKCgoKICAgIH0KCiAgICBmb3IoaT0wO2k8cTtpKyspCiAgICAgICAgcHJpbnRmKCIlZFxuIixhbnNzW2ldKTsKCn0K