//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
int a[N],b[N];
vector<vector<signed> > G(N);
int sum=0;

void dfs(vector<int> u,int v,int f){
	u.push_back(a[v]);
	if(v!=1){
		int t=b[u[u.size()-1]+1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,b[u[i]+1]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		if(vv==f) continue;
		dfs(u,vv,v);
	}
}

int solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	int m=unique(b+1,b+n+1)-(b+1);
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(b+1,b+n+1,a[i])-(b+1);
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%lld%lld",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> u;
	dfs(u,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
int a[N],b[N];
vector<vector<int> > G(N);
int sum=0;

void dfs(vector<int> u,int v,int f){
	u.push_back(a[v]);
	if(v!=1){
		int t=u[u.size()-1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(b[t],b[u[i]]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		if(vv==f) continue;
		dfs(u,vv,v);
	}
}

int solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	int m=unique(b+1,b+n+1)-b;
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(b+1,b+n+1,a[i])-b;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%lld%lld",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> u;
	dfs(u,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(vector<pair<ll,int> > vc,int u,int f){
	vector<pair<ll,int> > vv;
	vv.push_back(make_pair(a[u],1));
	for(int i=0;i<vc.size();i++){
		ll x=vc[i].first;
		int y=vc[i].second;
		ll t=gcd(x,a[u]);
		if(vv.back().first==t){
			vv.back().second+=y;
		}
		else{
			vv.push_back(make_pair(t,y));
		}
		sum+=1ll*t*y%mod;
	}
	swap(vc,vv);
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		dfs(vc,v,u);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<pair<ll,int> > vc;
	dfs(vc,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(vector<pair<ll,int> > vc,int u,int f){
	vector<pair<ll,int> > vv;
	vv.push_back(make_pair(a[u],1));
	for(int i=0;i<vc.size();i++){
		ll x=vc[i].first;
		int y=vc[i].second;
		ll t=gcd(x,a[u]);
		if(a[u]==t){
			vv.back().second+=y;
		}
		else{
			vv.push_back(make_pair(t,y));
		}
		sum=(sum+1ll*t*y)%mod;
	}
	swap(vc,vv);
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		dfs(vc,v,u);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<pair<ll,int> > vc;
	dfs(vc,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
int a[N];
vector<vector<int> > G(N),v(N);
int sum=0;

void dfs(vector<int> u,int v){
	u.push_back(a[v]);
	if(v!=1){
		int t=u[u.size()-1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,u[i]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		dfs(u,vv);
	}
}

int solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%lld%lld",&a,&b);
		G[a].push_back(b);
	}
	vector<int> u;
	dfs(u,1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(map<ll,int> hs,int u,int f){
	map<ll,int> hs1;
	for(map<ll,int>::iterator it=hs.begin();it!=hs.end();it++){
		ll t=gcd(a[u],it->first);
		int y=it->second;
		hs1[t]+=y;
		sum=(sum+1ll*t*y%mod)%mod;
	}
	hs.clear();
	hs1[a[u]]++;
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		dfs(hs1,v,u);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	map<ll,int> hs;
	dfs(hs,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(tr1::unordered_map<ll,int> hs,int u,int f){
	tr1::unordered_map<ll,int> hs1;
	for(tr1::unordered_map<ll,int>::iterator it=hs.begin();it!=hs.end();it++){
		ll t=gcd(a[u],it->first);
		int y=it->second;
		hs1[t]+=y;
		sum=(sum+1ll*t*y%mod)%mod;
	}
	hs.clear();
	hs1[a[u]]++;
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		dfs(hs1,v,u);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	tr1::unordered_map<ll,int> hs;
	dfs(hs,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
int a[N],b[N];
vector<vector<int> > G(N);
int sum=0;

void dfs(vector<int> u,int v,int f){
	u.push_back(a[v]);
	if(v!=1){
		int t=b[u[u.size()-1]+1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,b[u[i]+1]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		if(vv==f) continue;
		dfs(u,vv,v);
	}
}

int solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	int m=unique(b+1,b+n+1)-(b+1);
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(b+1,b+n+1,a[i])-(b+1);
		printf("%lld ",a[i]);
	}
	puts("");
	for(int i=1;i<=n;i++){
		printf("%lld ",b[i]);
	}
	puts("");
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%lld%lld",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> u;
	dfs(u,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
int a[N],b[N];
vector<vector<int> > G(N);
int sum=0;

void dfs(vector<int> u,int v,int f){
	u.push_back(a[v]);
	if(v!=1){
		int t=b[u[u.size()-1]+1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,b[u[i]+1]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		if(vv==f) continue;
		dfs(u,vv,v);
	}
}

int solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	int m=unique(b+1,b+n+1)-(b+1);
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(b+1,b+n+1,a[i])-(b+1);
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%lld%lld",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> u;
	dfs(u,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
int a[N];
vector<vector<int> > G(N),v(N);
int sum=0;

void dfs(vector<int> u,int v,int f){
	u.push_back(a[v]);
	if(v!=1){
		int t=u[u.size()-1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,u[i]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		if(vv==f) continue;
		dfs(u,vv,v);
	}
}

int solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%lld%lld",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> u;
	dfs(u,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
int a[N];
vector<vector<int> > G(N),v(N);
int sum=0;

void dfs(vector<int> u,int v){
	u.push_back(a[v]);
	if(v!=1){
		int t=u[u.size()-1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,u[i]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		dfs(u,vv);
	}
}

int solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%lld%lld",&a,&b);
		if(a>b) swap(a,b);
		G[a].push_back(b);
	}
	vector<int> u;
	dfs(u,1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N],b[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(vector<int> u,int v,int f){
	u.push_back(a[v]);
	if(v!=1){
		ll t=b[u[u.size()-1]+1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,b[u[i]+1]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		if(vv==f) continue;
		dfs(u,vv,v);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	int m=unique(b+1,b+n+1)-(b+1);
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(b+1,b+n+1,a[i])-(b+1);
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> u;
	dfs(u,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(tr1::unordered_map<ll,int> hs,int u,int f){
	tr1::unordered_map<ll,int> hs1;
	for(tr1::unordered_map<ll,int>::iterator it=hs.begin();it!=hs.end();it++){
		ll t=gcd(a[u],it->first);
		int y=it->second;
		hs1[t]+=y;
		sum=(sum+1ll*t*y%mod)%mod;
	}
	hs1[a[u]]++;
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		dfs(hs1,v,u);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	tr1::unordered_map<ll,int> hs;
	dfs(hs,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int n;
int a[N];
vector<vector<int> > G(N);
int sum=0;

void dfs(vector<int> u,int v,int f){
	u.push_back(a[v]);
	if(v!=1){
		int t=u[u.size()-1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,u[i]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		if(vv==f) continue;
		dfs(u,vv,v);
	}
}

int solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%lld%lld",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> u;
	dfs(u,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N],b[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(vector<int> u,int v,int f){
	u.push_back(a[v]);
	if(v!=1){
		ll t=b[u[u.size()-1]+1];
		for(int i=u.size()-2;~i;i--){
			t=gcd(t,b[u[i]+1]);
			sum=1ll*(sum+t)%mod;
		}
	}
	for(int i=0;i<G[v].size();i++){
		int vv=G[v][i];
		if(vv==f) continue;
		dfs(u,vv,v);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	int m=unique(b+1,b+n+1)-(b+1);
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(b+1,b+n+1,a[i])-(b+1);
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> u;
	dfs(u,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(unordered_map<ll,int> hs,int u,int f){
	unordered_map<ll,int> hs1;
	for(unordered_map<ll,int>::iterator it=hs.begin();it!=hs.end();it++){
		ll t=gcd(a[u],it->first);
		int y=it->second;
		hs1[t]+=y;
		sum=(sum+1ll*t*y%mod)%mod;
	}
	hs.clear();
	hs1[a[u]]++;
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		dfs(hs1,v,u);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	unordered_map<ll,int> hs;
	dfs(hs,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[100000 * 10];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<long long>> gcd1(n + 1);
  vector<vector<int>> gcd2(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    memset(g, 0, sizeof(g));
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (int i = 0; i < gcd1[v].size(); i++) {
          g[cg++] = {_gcd(gcd1[v][i], a[rt]), gcd2[v][i]};
        }
        gcd1[v].clear();
        gcd2[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd1[rt].push_back(g[last].first);
        gcd2[rt].push_back(sum);
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[1 << 12];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<pair<long long, int>>> gcd(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    memset(g, 0, sizeof(g));
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (auto &p: gcd[v]) {
          g[cg++] = {_gcd(p.first, a[rt]), p.second};
        }
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd[rt].push_back({g[last].first, sum});
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[1000001];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<long long>> gcd1(n + 1);
  vector<vector<int>> gcd2(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (int i = 0; i < gcd1[v].size(); i++) {
          g[cg++] = {_gcd(gcd1[v][i], a[rt]), gcd2[v][i]};
        }
        gcd1[v].clear();
        gcd2[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd1[rt].push_back(g[last].first);
        gcd2[rt].push_back(sum);
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
    assert(gcd1[rt].size() < 5000);
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[100000 * 500];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<pair<long long, int>>> gcd(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (auto &p: gcd[v]) {
          g[cg++] = {_gcd(p.first, a[rt]), p.second};
        }
        gcd[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd[rt].push_back({g[last].first, sum});
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? gcd(b, a % b) : a;
}
pair<long long, int> g[1 << 12];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<pair<long long, int>>> gcd(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    memset(g, 0, sizeof(g));
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (auto &p: gcd[v]) {
          g[cg++] = {_gcd(p.first, a[rt]), p.second};
        }
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd[rt].push_back({g[last].first, sum});
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[1 << 12];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<long long>> gcd1(n + 1);
  vector<vector<int>> gcd2(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    memset(g, 0, sizeof(g));
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (int i = 0; i < gcd1[v].size(); i++) {
          g[cg++] = {_gcd(gcd1[v][i], a[rt]), gcd2[v][i]};
        }
        gcd1[v].clear();
        gcd2[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd1[rt].push_back(g[last].first);
        gcd2[rt].push_back(sum);
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[1 << 12];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<pair<long long, int>>> gcd(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    memset(g, 0, sizeof(g));
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (auto &p: gcd[v]) {
          g[cg++] = {_gcd(p.first, a[rt]), p.second};
        }
        gcd[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd[rt].push_back({g[last].first, sum});
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[100000 * 4200];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<pair<long long, int>>> gcd(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (auto &p: gcd[v]) {
          g[cg++] = {_gcd(p.first, a[rt]), p.second};
        }
        gcd[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd[rt].push_back({g[last].first, sum});
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<pair<long long, int>>> gcd(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    gcd[rt].push_back({a[rt], 1});
    add(ans, a[rt] % mod);
    for (auto &p: gcd[fa]) {
      long long g = _gcd(p.first, a[rt]);
      add(ans, g % mod * p.second % mod);
      if (g == gcd[rt].back().first) gcd[rt].back().second += p.second;
      else gcd[rt].push_back({g, p.second});
    }
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
        graph[v].clear();
      }
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[1000001];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<long long>> gcd1(n + 1);
  vector<vector<int>> gcd2(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (int i = 0; i < gcd1[v].size(); i++) {
          g[cg++] = {_gcd(gcd1[v][i], a[rt]), gcd2[v][i]};
        }
        gcd1[v].clear();
        gcd2[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd1[rt].push_back(g[last].first);
        gcd2[rt].push_back(sum);
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[100000 * 1000];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<pair<long long, int>>> gcd(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (auto &p: gcd[v]) {
          g[cg++] = {_gcd(p.first, a[rt]), p.second};
        }
        gcd[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd[rt].push_back({g[last].first, sum});
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#ifdef osayes
#include "header.cpp"
#else
#define debug(...) 0
#endif
#include <bits/stdc++.h>
using namespace std;
void Main();
#if 1
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
#else
int main() { ios::sync_with_stdio(0); cin.tie(0); int x; cin >> x; while (~cin.peek()) Main(), cin.get(); return 0; }
#endif
const int mod = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long _gcd(long long a, long long b) {
  return b? _gcd(b, a % b) : a;
}
pair<long long, int> g[100000 * 1200];
int cg;
void Main() {
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<int>> graph(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<vector<pair<long long, int>>> gcd(n + 1);
  int ans = 0;
  function<void(int, int)> dfs = [&](int rt, int fa) {
    for (int &v: graph[rt]) {
      if (v != fa) {
        dfs(v, rt);
      }
    }
    cg = 0;
    g[cg++] = {a[rt], 1};
    for (auto &v: graph[rt]) {
      if (v != fa) {
        for (auto &p: gcd[v]) {
          g[cg++] = {_gcd(p.first, a[rt]), p.second};
        }
        gcd[v].clear();
      }
    }
    sort(g, g + cg);
    int last = 0, sum = g[0].second;
    for (int i = 1; i <= cg; i++) {
      if (i == cg || g[i].first != g[i - 1].first) {
        gcd[rt].push_back({g[last].first, sum});
        add(ans, g[last].first % mod * sum % mod);
        last = i;
        sum = g[i].second;
      } else sum += g[i].second;
    }
  };
  dfs(1, 0);
  cout << ans << endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>
#include<ctime>
#include<ctype.h>
#include<stdlib.h>
#include<bitset>
#include<algorithm>
#include<assert.h>
#include<numeric> //accumulate
#define endl "\n"
#define fi first
#define se second
#define forn(i,s,t) for(int i=(s);i<=(t);++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define rush() int MYTESTNUM;cin>>MYTESTNUM;while(MYTESTNUM--)
#define debug(x) printf("%d\n",x)
#define inf 0x3f3f3f3f
#define INF 1e18
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define ll long long
using namespace std;
const ll P=1e9+7;
ll mul(ll a, ll b){ll ans = 0;for(;b;a=a*2%P,b>>=1) if(b&1) ans=(ans+a)%P;return ans;}
ll qpow(ll a,ll n) {ll r=1;for (;n;a=a*a,n>>=1)if(n&1)r=r*a;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
const int maxn=1e5+5;

struct Solution
{
	int n;

	int head[maxn],ver[maxn<<1],nex[maxn<<1],tot;

	ll v[maxn];

	map<ll,int> dp[maxn];

	ll ans;

	void Prepare()
	{

	}

	inline void AddEdge(int x,int y)
	{
		ver[++tot]=y,nex[tot]=head[x],head[x]=tot;
	}

	bool Init()
	{
		if(sc(n)==1)
		{
			for(int i=1;i<=n;i++)
				scanf("%lld",&v[i]);
			for(int i=0;i<n-1;i++)
			{
				int x,y;
				sc2(x,y);
				AddEdge(x,y);
				AddEdge(y,x);
			}
			return 1;
		}

		return 0;
	}

	void Mod(ll& x)
	{
		if(x>=P) x%=P;
	}

	void Dfs(int x,int pa)
	{
		for(auto it:dp[pa])
		{
			ll tx=it.fi,ty=it.se;
			dp[x][__gcd(tx,v[x])]+=ty;
		}
		dp[x][v[x]]++;
		for(auto it:dp[x])
		{
			Mod(ans+=1ll*(it.fi)*(it.se));
		}
		for(int i=head[x];i;i=nex[i])
		{
			int y=ver[i];
			if(y==pa) continue;
			Dfs(y,x);
		}
	}

	void Solve()
	{
		Dfs(1,0);
		cout<<ans<<endl;
	}
}H;

signed main()
{
	H.Prepare();

	//rush()
	{
		H.Init();
		H.Solve();
	}

}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>
#include<ctime>
#include<ctype.h>
#include<stdlib.h>
#include<bitset>
#include<algorithm>
#include<assert.h>
#include<numeric> //accumulate
#define endl "\n"
#define fi first
#define se second
#define forn(i,s,t) for(int i=(s);i<=(t);++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define rush() int MYTESTNUM;cin>>MYTESTNUM;while(MYTESTNUM--)
#define debug(x) printf("%d\n",x)
#define inf 0x3f3f3f3f
#define INF 1e18
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define ll long long
using namespace std;
const ll P=1e9+7;
ll mul(ll a, ll b){ll ans = 0;for(;b;a=a*2%P,b>>=1) if(b&1) ans=(ans+a)%P;return ans;}
ll qpow(ll a,ll n) {ll r=1;for (;n;a=a*a,n>>=1)if(n&1)r=r*a;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
const int maxn=1e5+5;

struct Solution
{
	int n;

	int head[maxn],ver[maxn<<1],nex[maxn<<1],tot;

	ll v[maxn];

	ll dp[maxn];

	ll ans;

	int fa[maxn];

	void Prepare()
	{

	}

	inline void AddEdge(int x,int y)
	{
		ver[++tot]=y,nex[tot]=head[x],head[x]=tot;
	}

	bool Init()
	{
		if(sc(n)==1)
		{
			for(int i=1;i<=n;i++)
				scanf("%lld",&v[i]);
			for(int i=0;i<n-1;i++)
			{
				int x,y;
				sc2(x,y);
				AddEdge(x,y);
				AddEdge(y,x);
			}
			return 1;
		}

		return 0;
	}

	void Mod(ll& x)
	{
		if(x>=P) x%=P;
	}

	void Dfs(int x,int pa)
	{

		Mod(ans+=dp[x]);
		for(int i=head[x];i;i=nex[i])
		{
			int y=ver[i];
			if(y==pa) continue;
			dp[y]=__gcd(1ll*v[y],dp[x]);
			Dfs(y,x);
		}
	}

	void GetFa(int x,int pa)
	{
		fa[x]=pa;
		for(int i=head[x];i;i=nex[i])
		{
			int y=ver[i];
			if(y==pa) continue;
			GetFa(y,x);
		}
	}

	void Solve()
	{
		GetFa(1,0);
		for(int i=1;i<=n;i++)
		{
			dp[i]=v[i];
			Dfs(i,fa[i]);
			v[i]=-1;
		}
		cout<<ans%P<<endl;
	}

}H;

signed main()
{
	H.Prepare();

	//rush()
	{
		H.Init();
		H.Solve();
	}

}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>
#include<ctime>
#include<ctype.h>
#include<stdlib.h>
#include<bitset>
#include<algorithm>
#include<assert.h>
#include<numeric> //accumulate
#define endl "\n"
#define fi first
#define se second
#define forn(i,s,t) for(int i=(s);i<=(t);++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define rush() int MYTESTNUM;cin>>MYTESTNUM;while(MYTESTNUM--)
#define debug(x) printf("%d\n",x)
#define inf 0x3f3f3f3f
#define INF 1e18
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define ll long long
using namespace std;
const ll P=1e9+7;
ll mul(ll a, ll b){ll ans = 0;for(;b;a=a*2%P,b>>=1) if(b&1) ans=(ans+a)%P;return ans;}
ll qpow(ll a,ll n) {ll r=1;for (;n;a=a*a,n>>=1)if(n&1)r=r*a;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
const int maxn=1e5+5;

struct Solution
{
	int n;

	int head[maxn],ver[maxn<<1],nex[maxn<<1],tot;

	ll v[maxn];

	ll dp[maxn];

	ll ans;

	void Prepare()
	{

	}

	inline void AddEdge(int x,int y)
	{
		ver[++tot]=y,nex[tot]=head[x],head[x]=tot;
	}

	bool Init()
	{
		if(sc(n)==1)
		{
			for(int i=1;i<=n;i++)
				scanf("%lld",&v[i]);
			for(int i=0;i<n-1;i++)
			{
				int x,y;
				sc2(x,y);
				AddEdge(x,y);
				AddEdge(y,x);
			}
			return 1;
		}

		return 0;
	}

	void Mod(ll& x)
	{
		if(x>=P) x-=P;
	}

	void Dfs(int x,int pa)
	{

		Mod(ans+=dp[x]);
		for(int i=head[x];i;i=nex[i])
		{
			int y=ver[i];
			if(y==pa||v[y]<0) continue;
			dp[y]=__gcd(1ll*v[y],dp[x]);
			Dfs(y,x);
		}
	}

	void Solve()
	{
		for(int i=1;i<=n;i++)
		{
			dp[i]=v[i];
			Dfs(i,0);
			v[i]=-1;
		}
		cout<<ans%P<<endl;
	}

}H;

signed main()
{
	H.Prepare();

	//rush()
	{
		H.Init();
		H.Solve();
	}

}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>
#include<ctime>
#include<ctype.h>
#include<stdlib.h>
#include<bitset>
#include<algorithm>
#include<assert.h>
#include<numeric> //accumulate
#define endl "\n"
#define fi first
#define se second
#define forn(i,s,t) for(int i=(s);i<=(t);++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define rush() int MYTESTNUM;cin>>MYTESTNUM;while(MYTESTNUM--)
#define debug(x) printf("%d\n",x)
#define inf 0x3f3f3f3f
#define INF 1e18
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define ll long long
using namespace std;
const ll P=1e9+7;
ll mul(ll a, ll b){ll ans = 0;for(;b;a=a*2%P,b>>=1) if(b&1) ans=(ans+a)%P;return ans;}
ll qpow(ll a,ll n) {ll r=1;for (;n;a=a*a,n>>=1)if(n&1)r=r*a;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
const int maxn=1e5+5;

struct Solution
{
	int n;

	int head[maxn],ver[maxn<<1],nex[maxn<<1],tot;

	ll v[maxn];

	ll dp[maxn];

	ll ans;

	void Prepare()
	{

	}

	inline void AddEdge(int x,int y)
	{
		ver[++tot]=y,nex[tot]=head[x],head[x]=tot;
	}

	bool Init()
	{
		if(sc(n)==1)
		{
			for(int i=1;i<=n;i++)
				scanf("%lld",&v[i]);
			for(int i=0;i<n-1;i++)
			{
				int x,y;
				sc2(x,y);
				AddEdge(x,y);
				AddEdge(y,x);
			}
			return 1;
		}

		return 0;
	}

	void Mod(ll& x)
	{
		if(x>=P) x%=P;
	}

	void Dfs(int x,int pa)
	{

		Mod(ans+=dp[x]);
		for(int i=head[x];i;i=nex[i])
		{
			int y=ver[i];
			if(y==pa||v[y]<0) continue;
			dp[y]=__gcd(1ll*v[y],dp[x]);
			Dfs(y,x);
		}
	}

	void Solve()
	{
		for(int i=1;i<=n;i++)
		{
			dp[i]=v[i];
			Dfs(i,0);
			v[i]=-1;
		}
		cout<<ans%P<<endl;
	}

}H;

signed main()
{
	H.Prepare();

	//rush()
	{
		H.Init();
		H.Solve();
	}

}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>
#include<ctime>
#include<ctype.h>
#include<stdlib.h>
#include<bitset>
#include<algorithm>
#include<assert.h>
#include<numeric> //accumulate
#define endl "\n"
#define fi first
#define se second
#define forn(i,s,t) for(int i=(s);i<=(t);++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define rush() int MYTESTNUM;cin>>MYTESTNUM;while(MYTESTNUM--)
#define debug(x) printf("%d\n",x)
#define inf 0x3f3f3f3f
#define INF 1e18
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define ll long long
using namespace std;
const ll P=1e9+7;
ll mul(ll a, ll b){ll ans = 0;for(;b;a=a*2%P,b>>=1) if(b&1) ans=(ans+a)%P;return ans;}
ll qpow(ll a,ll n) {ll r=1;for (;n;a=a*a,n>>=1)if(n&1)r=r*a;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
const int maxn=1e5+5;

struct Solution
{
	int n;

	int head[maxn],ver[maxn<<1],nex[maxn<<1],tot;

	ll v[maxn];

	ll dp[maxn];

	ll ans;

	void Prepare()
	{

	}

	inline void AddEdge(int x,int y)
	{
		ver[++tot]=y,nex[tot]=head[x],head[x]=tot;
	}

	bool Init()
	{
		if(sc(n)==1)
		{
			for(int i=1;i<=n;i++)
				scanf("%lld",&v[i]);
			for(int i=0;i<n-1;i++)
			{
				int x,y;
				sc2(x,y);
				AddEdge(x,y);
				AddEdge(y,x);
			}
			return 1;
		}

		return 0;
	}

	void Mod(ll& x)
	{
		if(x>=P) x-=P;
	}

	void Dfs(int x,int pa)
	{

		Mod(ans+=dp[x]);
		for(int i=head[x];i;i=nex[i])
		{
			int y=ver[i];
			if(y==pa||v[y]<0) continue;
			dp[y]=__gcd(1ll*v[y],dp[x]);
			Dfs(y,x);
		}
	}

	void Solve()
	{

		for(int i=1;i<=n;i++)
		{
			dp[i]=v[i];
			Dfs(i,0);
			v[i]=-1;
		}
		cout<<ans<<endl;
	}

}H;

signed main()
{
	H.Prepare();

	//rush()
	{
		H.Init();
		H.Solve();
	}

}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<list>
#include<ctime>
#include<ctype.h>
#include<stdlib.h>
#include<bitset>
#include<algorithm>
#include<assert.h>
#include<numeric> //accumulate
#define endl "\n"
#define fi first
#define se second
#define forn(i,s,t) for(int i=(s);i<=(t);++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define rush() int MYTESTNUM;cin>>MYTESTNUM;while(MYTESTNUM--)
#define debug(x) printf("%d\n",x)
#define inf 0x3f3f3f3f
#define INF 1e18
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define ll long long
using namespace std;
const ll P=1e9+7;
ll mul(ll a, ll b){ll ans = 0;for(;b;a=a*2%P,b>>=1) if(b&1) ans=(ans+a)%P;return ans;}
ll qpow(ll a,ll n) {ll r=1;for (;n;a=a*a,n>>=1)if(n&1)r=r*a;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
const int maxn=1e5+5;

struct Solution
{
	int n;

	int head[maxn],ver[maxn<<1],nex[maxn<<1],tot;

	ll v[maxn];

	ll dp[maxn];

	ll ans;

	int fa[maxn];

	void Prepare()
	{

	}

	inline void AddEdge(int x,int y)
	{
		ver[++tot]=y,nex[tot]=head[x],head[x]=tot;
	}

	bool Init()
	{
		if(sc(n)==1)
		{
			for(int i=1;i<=n;i++)
				scanf("%lld",&v[i]);
			for(int i=0;i<n-1;i++)
			{
				int x,y;
				sc2(x,y);
				AddEdge(x,y);
				AddEdge(y,x);
			}
			return 1;
		}

		return 0;
	}

	void Mod(ll& x)
	{
		if(x>=P) x%=P;
	}

	void Dfs(int x,int pa)
	{
		Mod(ans+=dp[x]);
		for(int i=head[x];i;i=nex[i])
		{
			int y=ver[i];
			if(y==pa) continue;
			dp[y]=__gcd(v[y],dp[x]);
			Dfs(y,x);
		}
	}

	void GetFa(int x,int pa)
	{
		dp[x]=v[x];
		Dfs(x,pa);
		for(int i=head[x];i;i=nex[i])
		{
			int y=ver[i];
			if(y==pa) continue;
			GetFa(y,x);
		}
	}

	void Solve()
	{
		GetFa(1,0);
		cout<<ans%P<<endl;
	}

}H;

signed main()
{
	H.Prepare();

	//rush()
	{
		H.Init();
		H.Solve();
	}

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
int n,m,T;
int a[maxn];
vi g[maxn];
vector<pair<int,int>> tmp[maxn];
ll ans;
map<ll,int>M;
void dfs(int u,int fa){
	ll d;
	for(auto v:g[u]){
		if(v==fa)continue;
		M.clear();
		M[a[v]]++;
		for(auto x:tmp[u]){
			d=gcd(x.fi,a[v]);
			M[d]+=x.se;
		}
		for(auto y:M){
			tmp[v].pb({y.fi,y.se});
			ans=(ans+1ll*y.fi*y.se%mod)%mod;
		}
		dfs(v,u);
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n-1;i++){
		int uu,vv;
		scanf("%d%d",&uu,&vv);
		g[uu].pb(vv);
		g[vv].pb(uu);
	}
	ans=0;
	tmp[1].pb({a[1],1});
	ans=a[1];
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
int n,m,T;
ll a[maxn];
vi g[maxn];
vector<pair<ll,int>> tmp[maxn];
ll ans;
map<ll,int>M;
void dfs(int u,int fa){
	ll d;
	for(auto v:g[u]){
		if(v==fa)continue;
		M.clear();
		M[a[v]]++;
		for(auto x:tmp[u]){
			d=gcd(x.fi,a[v]);
			M[d]+=x.se;
		}
		for(auto y:M){
			tmp[v].pb({y.fi,y.se});
			ans=(ans+1ll*y.fi%mod*y.se%mod)%mod;
		}
		dfs(v,u);
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%I64d",&a[i]);
	}
	for(int i=0;i<n-1;i++){
		int uu,vv;
		scanf("%d%d",&uu,&vv);
		g[uu].pb(vv);
		g[vv].pb(uu);
	}
	ans=0;
	tmp[1].pb({a[1],1});
	ans=a[1]%mod;
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
int n,m,T;
int a[maxn];
vi g[maxn];
vector<pair<ll,int>> tmp[maxn];
ll ans;
map<ll,int>M;
void dfs(int u,int fa){
	ll d;
	for(auto v:g[u]){
		if(v==fa)continue;
		M.clear();
		M[a[v]]++;
		for(auto x:tmp[u]){
			d=gcd(x.fi,a[v]);
			M[d]+=x.se;
		}
		for(auto y:M){
			tmp[v].pb({y.fi,y.se});
			ans=(ans+1ll*y.fi%mod*y.se%mod)%mod;
		}
		dfs(v,u);
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n-1;i++){
		int uu,vv;
		scanf("%d%d",&uu,&vv);
		g[uu].pb(vv);
		g[vv].pb(uu);
	}
	ans=0;
	tmp[1].pb({a[1],1});
	ans=a[1];
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
int n,m,T;
int a[maxn];
vi g[maxn];
vector<pair<int,int>> tmp[maxn];
ll ans;
map<ll,int>M;
void dfs(int u,int fa){
	ll d;
	for(auto v:g[u]){
		if(v==fa)continue;
		M.clear();
		M[a[v]]++;
		for(auto x:tmp[u]){
			d=gcd(x.fi,a[v]);
			M[d]+=x.se;
		}
		for(auto y:M){
			tmp[v].pb({y.fi,y.se});
			ans=(ans+1ll*y.fi%mod*y.se%mod)%mod;
		}
		dfs(v,u);
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n-1;i++){
		int uu,vv;
		scanf("%d%d",&uu,&vv);
		g[uu].pb(vv);
		g[vv].pb(uu);
	}
	ans=0;
	tmp[1].pb({a[1],1});
	ans=a[1];
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ri x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=1e5+5,p=1e9+7;
struct edg{
	int nxt,to;
}e[N<<1];
int head[N],cnt,dep[N],fa[N],an[N][18],n;
ll a[N],g[N][18];

inline void add(ri u,ri v){e[++cnt].nxt=head[u];head[u]=cnt;e[cnt].to=v;}
inline ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
inline void dfs(ri u){
	dep[u]=dep[fa[u]]+1;
	g[u][0]=gcd(a[u],a[fa[u]]);an[u][0]=fa[u];
	rep(i,1,17){
		an[u][i]=an[an[u][i-1]][i-1];
		g[u][i]=gcd(g[u][i-1],g[an[u][i-1]][i-1]);
	}
	for(ri i=head[u];i;i=e[i].nxt){
		ri v=e[i].to;
		if(v==fa[u]) continue;
		fa[v]=u;
		dfs(v);
	}
}
inline ll calc(ri u,ri d){
	//cout<<"calc:"<<u<<' '<<d;
	ll x=0;d=dep[u]-d;//cout<<"  "<<d<<endl;
	REP(i,17,0){
		if(dep[an[u][i]]>d) x=gcd(x,g[u][i]),u=an[u][i];
	}
	//cout<<"   "<<u<<' '<<dep[u]<<' '<<gcd(x,g[u][0])<<endl;
	return gcd(x,g[u][0]);
}

int main()
{
	n=read();ri ans=0;
	rep(i,1,n){
		a[i]=readll();
		ans=(ans+(a[i]%p))%p;
	}
	rep(i,1,n-1){
		ri u=read(),v=read();
		add(u,v);add(v,u);
	}
	dfs(1);
	rep(i,1,n){
		ri u=1,d=dep[i]-1;//������u��
		ll cur=calc(i,u);
		while(u<=d){
			ri l=u,r=d,res=l;
			while(l<=r){
				ri mid=(l+r)>>1;
				if(calc(i,mid)==cur) res=mid,l=mid+1;
				else r=mid-1;
			}
			ans=(ans+1ll*(cur%p)*(res-u+1)%p)%p;//cout<<i<<' '<<cur<<' '<<(res-u+1)<<endl;
			u=res+1;cur=calc(i,u);
		}
	}
	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ri x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=1e5+5,p=1e9+7;
struct edg{
	int nxt,to;
}e[N<<1];
int head[N],cnt,dep[N],fa[N],an[N][18],n;
ll a[N],g[N][18];

inline void add(ri u,ri v){e[++cnt].nxt=head[u];head[u]=cnt;e[cnt].to=v;}
inline ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
inline void dfs(ri u){
	dep[u]=dep[fa[u]]+1;
	g[u][0]=gcd(a[u],a[fa[u]]);an[u][0]=fa[u];
	rep(i,1,17){
		an[u][i]=an[an[u][i-1]][i-1];
		g[u][i]=gcd(g[u][i-1],g[an[u][i-1]][i-1]);
	}
	for(ri i=head[u];i;i=e[i].nxt){
		ri v=e[i].to;
		if(v==fa[u]) continue;
		fa[v]=u;
		dfs(v);
	}
}

int main()
{
	n=read();ri ans=0;
	rep(i,1,n){
		a[i]=readll();
		ans=(ans+(a[i]%p))%p;
	}
	rep(i,1,n-1){
		ri u=read(),v=read();
		add(u,v);add(v,u);
	}
	dfs(1);
	rep(i,1,n){
		ri u=fa[i];ll cur=g[i][0];
		while(u){
			ri v=u;
			REP(j,17,0)
				if(g[v][j]%cur==0) v=an[v][j];
			if(v==0) v=1;
			ans=(ans+1ll*(cur%p)*(dep[u]-dep[v]+1)%p)%p;
			cur=gcd(cur,a[fa[v]]);u=fa[v];
		}
	}
	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ri x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=1e5+5,p=1e9+7;
struct edg{
	int nxt,to;
}e[N<<1];
int head[N],cnt,dep[N],fa[N],an[N][18],n;
ll a[N],g[N][18];

inline void add(ri u,ri v){e[++cnt].nxt=head[u];head[u]=cnt;e[cnt].to=v;}
inline ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
inline void dfs(ri u){
	dep[u]=dep[fa[u]]+1;
	g[u][0]=gcd(a[u],a[fa[u]]);an[u][0]=fa[u];
	rep(i,1,17){
		an[u][i]=an[an[u][i-1]][i-1];
		g[u][i]=gcd(g[u][i-1],g[an[u][i-1]][i-1]);
	}
	for(ri i=head[u];i;i=e[i].nxt){
		ri v=e[i].to;
		if(v==fa[u]) continue;
		fa[v]=u;
		dfs(v);
	}
}

int main()
{
	n=read();ri ans=0;
	rep(i,1,n){
		a[i]=readll();
		ans=(ans+(a[i]%p))%p;
	}
	rep(i,1,n-1){
		ri u=read(),v=read();
		add(u,v);add(v,u);
	}
	dfs(1);
	rep(i,1,n){
		ri u=fa[i];ll cur=g[i][0];
		while(u){
			ri v=u;
			REP(j,17,0)
				if(gcd(g[v][j],cur)==cur) v=an[v][j];
			if(v==0) v=1;
			ans=(ans+1ll*(cur%p)*(dep[u]-dep[v]+1)%p)%p;
			cur=gcd(cur,a[fa[v]]);u=fa[v];
		}
	}
	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ri x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=1e5+5,p=1e9+7;
struct edg{
	int nxt,to;
}e[N<<1];
int head[N],cnt,dep[N],fa[N],an[N][18],n;
ll a[N],g[N][18];

inline void add(ri u,ri v){e[++cnt].nxt=head[u];head[u]=cnt;e[cnt].to=v;}
inline ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
inline void dfs(ri u){
	dep[u]=dep[fa[u]]+1;
	g[u][0]=gcd(a[u],a[fa[u]]);an[u][0]=fa[u];
	rep(i,1,17){
		an[u][i]=an[an[u][i-1]][i-1];
		g[u][i]=gcd(g[u][i-1],g[an[u][i-1]][i-1]);
	}
	for(ri i=head[u];i;i=e[i].nxt){
		ri v=e[i].to;
		if(v==fa[u]) continue;
		fa[v]=u;
		dfs(v);
	}
}

int main()
{
	n=read();ri ans=0;
	rep(i,1,n){
		a[i]=readll();
		ans=(ans+(a[i]%p))%p;
	}
	rep(i,1,n-1){
		ri u=read(),v=read();
		add(u,v);add(v,u);
	}
	dfs(1);
	rep(i,1,n){
		ri u=fa[i];ll cur=g[i][0];
		while(u){
			ri v=u;
			REP(j,17,0)
				if(!cur||g[v][j]%cur==0) v=an[v][j];
			if(v==0) v=1;
			ans=(ans+1ll*(cur%p)*(dep[u]-dep[v]+1)%p)%p;
			cur=gcd(cur,a[fa[v]]);u=fa[v];
		}
	}
	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ri x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=1e5+5,p=1e9+7;
struct edg{
	int nxt,to;
}e[N<<1];
int head[N],cnt,dep[N],fa[N],an[N][18],n;
ll a[N],g[N][18];

inline void add(ri u,ri v){e[++cnt].nxt=head[u];head[u]=cnt;e[cnt].to=v;}
inline ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
inline void dfs(ri u){
	dep[u]=dep[fa[u]]+1;
	g[u][0]=gcd(a[u],a[fa[u]]);an[u][0]=fa[u];
	rep(i,1,17) g[u][i]=gcd(g[u][i-1],g[an[u][i-1]][i-1]);
	for(ri i=head[u];i;i=e[i].nxt){
		ri v=e[i].to;
		if(v==fa[u]) continue;
		fa[v]=u;
		dfs(v);
	}
}
inline ll calc(ri u,ri d){
	//cout<<"calc:"<<u<<' '<<d;
	ll x=0;d=dep[u]-d;
	REP(i,17,0)
		if(dep[an[u][i]]>d) x=gcd(x,g[u][i]),u=an[u][i];
	//cout<<"   "<<u<<' '<<gcd(x,g[u][0])<<endl;
	return gcd(x,g[u][0]);
}

int main()
{
	n=read();ri ans=0;
	rep(i,1,n){
		a[i]=readll();
		ans=(ans+(a[i]%p))%p;
	}
	rep(i,1,n-1){
		ri u=read(),v=read();
		add(u,v);add(v,u);
	}
	dfs(1);
	rep(i,1,n){
		ri u=1,d=dep[i]-1;//������u��
		ll cur=calc(i,u);
		while(u<=d){
			ri l=u,r=d,res=l;
			while(l<=r){
				ri mid=(l+r)>>1;
				if(calc(i,mid)==cur) res=mid,l=mid+1;
				else r=mid-1;
			}
			ans=(ans+1ll*(cur%p)*(res-u+1)%p)%p;//cout<<i<<' '<<cur<<' '<<(res-u+1)<<endl;
			u=res+1;cur=calc(i,u);
		}
	}
	write(ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lld I64d

const int MAX = 100000;
const long long MOD = 1000000007LL;

long long a[MAX+10];

int head[MAX+10], nxt[MAX*2+10], to[MAX*2+10], tot;
inline void init(int n){
    tot = -1; memset(head, -1, (n+5)*sizeof(int));
}
inline void addedge(int u, int v){
    nxt[++tot] = head[u];
    to[head[u] = tot] = v;
}

long long gcd(long long a, long long b){ return b ? gcd(b, a%b) : a; }

long long ans;
typedef unordered_map<long long, int> UMP;
void dfs(int u, int fa, UMP& faump){
    UMP ump; ++ump[a[u]];
    for (int e = head[u]; ~e; e = nxt[e]){
        int v = to[e];
        if (v != fa){
            dfs(v, u, ump);
        }
    }
    for (auto &it : ump){
        ans = (ans + it.first * it.second) % MOD;
        faump[gcd(a[fa], it.first)] += it.second;
    }
}

int main(){
    int n, u ,v;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%lld", a+i);
    init(n);
    for (int i = 1; i <= n-1; ++i){
        scanf("%d %d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    UMP tmp; dfs(1, 0, tmp);
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 100000;
const long long MOD = 1000000007LL;

long long a[MAX+10];

int head[MAX+10], nxt[MAX*2+10], to[MAX*2+10], tot;
inline void init(int n){
    tot = -1; memset(head, -1, (n+5)*sizeof(int));
}
inline void addedge(int u, int v){
    nxt[++tot] = head[u];
    to[head[u] = tot] = v;
}

long long gcd(long long a, long long b){ return b ? gcd(b, a%b) : a; }

long long ans;
unordered_map<long long, int> ump[MAX+10];
void dfs(int u, int fa){
    long long t = a[u];
    ++ump[u][t];
    for (int e = head[u]; ~e; e = nxt[e]){
        int v = to[e];
        if (v != fa){
            dfs(v, u);
            for (auto &it : ump[v]) ump[u][gcd(t, it.first)] += it.second;
        }
    }
    for (auto &it : ump[u]){
        ans = (ans + it.first * it.second) % MOD;
    }
}

int main(){
    int n, u ,v;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%I64d", a+i);
    init(n);
    for (int i = 1; i <= n-1; ++i){
        scanf("%d %d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    dfs(1, 0);
    printf("%I64d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 100000;
const long long MOD = 1000000007LL;

long long a[MAX+10];

int head[MAX+10], nxt[MAX*2+10], to[MAX*2+10], tot;
inline void init(int n){
    tot = -1; memset(head, -1, (n+5)*sizeof(int));
}
inline void addedge(int u, int v){
    nxt[++tot] = head[u];
    to[head[u] = tot] = v;
}

long long gcd(long long a, long long b){ return b ? gcd(b, a%b) : a; }

long long ans;
typedef unordered_map<long long, int> UMP;
void dfs(int u, int fa, UMP& faump){
    UMP ump; ++ump[a[u]];
    for (auto it : faump){
        ump[gcd(a[u], it.first)] += it.second;
    }
    for (auto &it : ump){
        ans = (ans + it.first * it.second) % MOD;
    }
    for (int e = head[u]; ~e; e = nxt[e]){
        int v = to[e];
        if (v != fa){
            dfs(v, u, ump);
        }
    }
}

int main(){
    int n, u ,v;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%I64d", a+i);
    init(n);
    for (int i = 1; i <= n-1; ++i){
        scanf("%d %d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    UMP tmp; dfs(1, 0, tmp);
    printf("%I64d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lld I64d

const int MAX = 100000;
const long long MOD = 1000000007;

long long a[MAX+10];

int head[MAX+10], nxt[MAX+10], to[MAX+10], tot;
inline void init(int n){
    tot = -1; memset(head, -1, (n+5)*sizeof(int));
}
inline void addedge(int u, int v){
    nxt[++tot] = head[u];
    to[head[u] = tot] = v;
}

long long gcd(long long a, long long b){ return b ? gcd(b, a%b) : a; }

long long ans;
typedef unordered_map<long long, int> UMP;
void dfs(int u, int fa, UMP& faump){
    UMP ump; ++ump[a[u]];
    for (int e = head[u]; ~e; e = nxt[e]){
        int v = to[e];
        if (v != fa){
            dfs(v, u, ump);
        }
    }
    for (auto &it : ump){
        ans = (ans + it.first * it.second) % MOD;
        faump[gcd(a[fa], it.first)] += it.second;
    }
}

int main(){
    int n, u ,v;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%lld", a+i);
    init(n);
    for (int i = 1; i <= n-1; ++i){
        scanf("%d %d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    UMP tmp; dfs(1, 0, tmp);
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 100000;
const long long MOD = 1000000007LL;

long long a[MAX+10];

int head[MAX+10], nxt[MAX*2+10], to[MAX*2+10], tot;
inline void init(int n){
    tot = -1; memset(head, -1, (n+5)*sizeof(int));
}
inline void addedge(int u, int v){
    nxt[++tot] = head[u];
    to[head[u] = tot] = v;
}

long long gcd(long long a, long long b){ return b ? gcd(b, a%b) : a; }

long long ans;
unordered_map<long long, int> ump[MAX+10];
void dfs(int u, int fa){
    int t = a[u];
    ++ump[u][t];
    for (int e = head[u]; ~e; e = nxt[e]){
        int v = to[e];
        if (v != fa){
            dfs(v, u);
            for (auto &it : ump[v]) ump[u][gcd(t, it.first)] += it.second;
        }
    }
    for (auto &it : ump[u]){
        ans = (ans + it.first * it.second) % MOD;
    }
}

int main(){
    int n, u ,v;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%I64d", a+i);
    init(n);
    for (int i = 1; i <= n-1; ++i){
        scanf("%d %d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    dfs(1, 0);
    printf("%I64d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 100000;
const long long MOD = 1000000007;

long long a[MAX+10];

int head[MAX+10], nxt[MAX+10], to[MAX+10], tot;
inline void init(int n){
    tot = -1; memset(head, -1, (n+5)*sizeof(int));
}
inline void addedge(int u, int v){
    nxt[++tot] = head[u];
    to[head[u] = tot] = v;
}

long long gcd(long long a, long long b){ return b ? gcd(b, a%b) : a; }

long long ans;
typedef unordered_map<long long, int> UMP;
void dfs(int u, int fa, UMP& faump){
    UMP ump; ++ump[a[u]];
    for (int e = head[u]; ~e; e = nxt[e]){
        int v = to[e];
        if (v != fa){
            dfs(v, u, ump);
        }
    }
    for (auto &it : ump){
        ans = (ans + it.first * it.second) % MOD;
        faump[gcd(a[fa], it.first)] += it.second;
    }
}

int main(){
    int n, u ,v;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%I64d", a+i);
    init(n);
    for (int i = 1; i <= n-1; ++i){
        scanf("%d %d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    UMP tmp; dfs(1, 0, tmp);
    printf("%I64d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAX 200010
#define LL long long
#define MOD 1000000007

map<LL,int> mp[MAX];
vector<int> e[MAX];
int ans;
LL a[MAX];
map<LL,int>::iterator mit;

LL gcd(LL x,LL y){
    if(x==0)return y;
    if(y==0)return x;
    return gcd(y,x%y);
}

void dfs(int x,int y){
    mp[x][a[x]]++;
    ans=(ans+a[x])%MOD;
    for(int i=0;i<e[x].size();i++){
        int to=e[x][i];
        if(to==y)continue;
        dfs(to,x);
        for(mit=mp[to].begin();mit!=mp[to].end();mit++){
            LL res=gcd(mit->first,a[x]);
            int cnt=mit->second;
            ans=(ans+1LL*cnt*res%MOD)%MOD;
            mp[x][res]+=cnt;
        }
        mp[to].clear();
    }
}

int main()
{
    int n,x,y;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=1;i<n;i++){
        scanf("%d %d",&x,&y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    dfs(1,1);
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAX 200010
#define LL long long
#define MOD 1000000007

map<int,int> mp[MAX];
vector<int> e[MAX];
int ans;
int a[MAX];
map<int,int>::iterator mit;

int gcd(int x,int y){
    if(x==0)return y;
    if(y==0)return x;
    return gcd(y,x%y);
}

void dfs(int x,int y){
    mp[x][a[x]]++;
    ans=(ans+a[x])%MOD;
    for(int i=0;i<e[x].size();i++){
        int to=e[x][i];
        if(to==y)continue;
        dfs(to,x);

        for(mit=mp[to].begin();mit!=mp[to].end();mit++){
            int res=gcd(mit->first,a[x]);
            int cnt=mit->second;
            ans=(ans+1LL*cnt*res%MOD)%MOD;
            mp[x][res]+=cnt;
        }
    }
}

int main()
{
    int n,x,y;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<n;i++){
        scanf("%d %d",&x,&y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    dfs(1,1);
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAX 200010
#define LL long long
#define MOD 1000000007

struct node{
	LL res;
	int cnt;

	node(){
	}

	node(LL r,int c){
		res=r;
		cnt=c;
	}
};
vector<node> ne[MAX];
node rr[MAX];

bool cmp(node a,node b){
	return a.res<b.res;
}

vector<int> e[MAX];

LL ans;
LL a[MAX];

LL gcd(LL x,LL y){
    if(x==0)return y;
    if(y==0)return x;
    return gcd(y,x%y);
}

void dfs(int x,int y){

    int cnt=0;
    for(int i=0;i<e[x].size();i++){
        int to=e[x][i];
        if(to==y)continue;
        dfs(to,x);
    }

    rr[++cnt].res=a[x];
    rr[cnt].cnt=1;
    for(int i=0;i<e[x].size();i++){
        int to=e[x][i];
        if(to==y)continue;
        for(int j=0;j<ne[to].size();j++){
			rr[++cnt].res=gcd(ne[to][j].res,a[x]);
			rr[cnt].cnt=ne[to][j].cnt;
        }
        ne[to].clear();
    }
    sort(rr+1,rr+cnt+1,cmp);

	LL xx=rr[1].res;
    int yy=rr[1].cnt;
    for(int i=2;i<=cnt;i++){
		if(rr[i].res==x){
			yy+=rr[i].cnt;
		}
		else{
			ans=(ans+xx*yy)%MOD;
			ne[x].push_back(node(xx,yy));
			xx=rr[i].res;
			yy=rr[i].cnt;
		}
    }

    ans=(ans+xx*yy)%MOD;
	ne[x].push_back(node(xx,yy));

}

int main()
{
    int n,x,y;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=1;i<n;i++){
        scanf("%d %d",&x,&y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    dfs(1,1);
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAX 200010
#define LL long long
#define MOD 1000000007

map<LL,int> mp[MAX];
vector<int> e[MAX];
int ans;
LL a[MAX];
map<LL,int>::iterator mit;

LL gcd(LL x,LL y){
    if(x==0)return y;
    if(y==0)return x;
    return gcd(y,x%y);
}

void dfs(int x,int y){
    mp[x][a[x]]++;
    ans=(ans+a[x])%MOD;
    for(int i=0;i<e[x].size();i++){
        int to=e[x][i];
        if(to==y)continue;
        dfs(to,x);
        for(mit=mp[to].begin();mit!=mp[to].end();mit++){
            LL res=gcd(mit->first,a[x]);
            int cnt=mit->second;
            ans=(ans+1LL*cnt*res%MOD)%MOD;
            mp[x][res]+=cnt;
        }
    }
}

int main()
{
    int n,x,y;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=1;i<n;i++){
        scanf("%d %d",&x,&y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    dfs(1,1);
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAX 200010
#define LL long long
#define MOD 1000000007

inline bool scan_d(LL &num)
{
    char in;bool IsN=false;
    in=getchar();
    if(in==EOF) return false;
    while(in!='-'&&(in<'0'||in>'9')) in=getchar();
    if(in=='-'){ IsN=true;num=0;}
    else num=in-'0';
    while(in=getchar(),in>='0'&&in<='9'){
            num*=10,num+=in-'0';
    }
    if(IsN) num=-num;
    return true;
}

inline bool scan_d(int &num)
{
    char in;bool IsN=false;
    in=getchar();
    if(in==EOF) return false;
    while(in!='-'&&(in<'0'||in>'9')) in=getchar();
    if(in=='-'){ IsN=true;num=0;}
    else num=in-'0';
    while(in=getchar(),in>='0'&&in<='9'){
            num*=10,num+=in-'0';
    }
    if(IsN) num=-num;
    return true;
}

struct node{

	LL res;
	int cnt;

	node(){
	}

	node(LL r,int c){
		res=r;
		cnt=c;
	}
};

vector<node> ne[MAX];
node rr[MAX];
vector<int> e[MAX];

bool cmp(node a,node b){
	return a.res<b.res;
}

LL ans;
LL a[MAX];

LL gcd(LL x,LL y){
    if(x==0)return y;
    if(y==0)return x;
    return gcd(y,x%y);
}

void dfs(int x,int y){

    int cnt=0;
    rr[++cnt].res=a[x];
    rr[cnt].cnt=1;
    for(int i=0;i<ne[y].size();i++){
        rr[++cnt].res=gcd(ne[y][i].res,a[x]);
        rr[cnt].cnt=ne[y][i].cnt;
    }
    sort(rr+1,rr+cnt+1,cmp);
	LL xx=rr[1].res;
    int yy=rr[1].cnt;
        for(int i=2;i<=cnt;i++){
		if(rr[i].res==xx){
			yy+=rr[i].cnt;
		}
		else{
			ans=(ans+xx*yy)%MOD;
			ne[x].push_back(node(xx,yy));
			xx=rr[i].res;
			yy=rr[i].cnt;
		}
    }
    ans=(ans+xx*yy)%MOD;
	ne[x].push_back(node(xx,yy));

    for(int i=0;i<e[x].size();i++){
        int to=e[x][i];
        if(to==y)continue;
        dfs(to,x);
    }
}

int main(){

    int n,x,y;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scan_d(a[i]);
    }
    for(int i=1;i<n;i++){

		scan_d(x);
		scan_d(y);

        e[x].push_back(y);
        e[y].push_back(x);
    }
    dfs(1,1);
    printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAX 200010
#define LL long long
#define MOD 1000000007

struct node{
	LL res;
	int cnt;

	node(){
	}

	node(LL r,int c){
		res=r;
		cnt=c;
	}
};
vector<node> ne[MAX];
node rr[MAX];

bool cmp(node a,node b){
	return a.res<b.res;
}

vector<int> e[MAX];

LL ans;
LL a[MAX];

LL gcd(LL x,LL y){
    if(x==0)return y;
    if(y==0)return x;
    return gcd(y,x%y);
}

void dfs(int x,int y){

    for(int i=0;i<e[x].size();i++){
        int to=e[x][i];
        if(to==y)continue;
        dfs(to,x);
    }

    int cnt=0;
    rr[++cnt].res=a[x];
    rr[cnt].cnt=1;
    for(int i=0;i<e[x].size();i++){
        int to=e[x][i];
        if(to==y)continue;

        for(int j=0;j<ne[to].size();j++){
			rr[++cnt].res=gcd(ne[to][j].res,a[x]);
			rr[cnt].cnt=ne[to][j].cnt;
        }

        ne[to].clear();
    }
    sort(rr+1,rr+cnt+1,cmp);

	LL xx=rr[1].res;
    int yy=rr[1].cnt;
    for(int i=2;i<=cnt;i++){
		if(rr[i].res==x){
			yy+=rr[i].cnt;
		}
		else{
			ans=(ans+xx*yy%MOD)%MOD;
			ne[x].push_back(node(xx,yy));

			xx=rr[i].res;
			yy=rr[i].cnt;
		}
    }

    ans=(ans+xx*yy%MOD)%MOD;
	ne[x].push_back(node(xx,yy));

}

int main()
{
    int n,x,y;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=1;i<n;i++){
        scanf("%d %d",&x,&y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    dfs(1,1);
    printf("%lld\n",ans);
    return 0;
}


//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const ll inf = 1e18;
const int LOG = 20;
const int mod = 1e9 + 7;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

vector<ll> v[N];

ll timer;
ll height[N];
ll up[N][LOG];
ll gg[N][LOG];
ll in[N], out[N];

void Dfs(ll node, ll Par, ll cur){
    in[node] = ++timer;
    height[node] = cur;
    up[node][0] = Par;
    if(node == 1)   gg[node][0] = a[node];
    else    gg[node][0] = __gcd(a[node], a[Par]);
    for(int i = 1; i < LOG; ++i){
        up[node][i] = up[up[node][i - 1]][i - 1];
        gg[node][i] = __gcd(gg[up[node][i - 1]][i - 1], gg[node][i - 1]);
    }

    for(auto i: v[node]){
        if(i != Par) Dfs(i, node, cur + 1);
    }
    out[node] = ++timer;
}

bool isAncest(ll u, ll v){ //pahla wala ancestor h dusre wale ka??
    return in[u] <= in[v] && out[v] <= out[u];
}

ll get(ll u, ll v){
    ll ans = a[u];
    for(int i = LOG - 1; i >= 0; --i){
        if(isAncest(v, up[u][i])){
            ans = __gcd(ans, gg[u][i]);
            u = up[u][i];
        }
    }
    return ans;
}

void solve(){
    ll n, x, y;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; ++i){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    Dfs(1, 1, 0);
    for(int i = 1; i <= n; ++i){
        ll u = i;
        while(true){
            ll curgcd = get(i, u);
            ll prev = u;
            for(int j = LOG - 1; j >= 0 ; --j){
                if(curgcd == get(i, up[u][j])) u = up[u][j];
            }
            ll val = 1LL * (height[prev] - height[u] + 1) * curgcd % mod;
            res = (res + val) % mod;
            if(u == 1)  break;
            u = up[u][0];
        }
    }
    cout << res;
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro


//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const ll inf = 1e18;
const int LOG = 18;
const int mod = 1e9 + 7;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

vector<ll> v[N];

ll timer;
ll height[N];
ll up[N][LOG];
ll gg[N][LOG];
ll in[N], out[N];

void Dfs(ll node, ll Par, ll cur){
    in[node] = ++timer;
    height[node] = cur;
    up[node][0] = Par;
    if(node == 1)   gg[node][0] = a[node];
    else    gg[node][0] = __gcd(a[node], a[Par]);
    for(int i = 1; i < LOG; ++i){
        up[node][i] = up[up[node][i - 1]][i - 1];
        gg[node][i] = __gcd(gg[up[node][i - 1]][i - 1], gg[node][i - 1]);
    }

    for(auto i: v[node]){
        if(i != Par) Dfs(i, node, cur + 1);
    }
    out[node] = ++timer;
}

bool isAncest(ll u, ll v){ //pahla wala ancestor h dusre wale ka??
    return in[u] <= in[v] && out[v] <= out[u];
}

ll get(ll u, ll v){
    ll j = (int)log2(height[u] - height[v] + 1);
    ll ans =  a[u];
    for(int i = j; i >= 0; --i){
        if(isAncest(v, up[u][i])){
            ans = __gcd(ans, gg[u][i]);
            u = up[u][i];
        }
    }
    return ans;
}

void solve(){
    ll n, x, y;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; ++i){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    Dfs(1, 1, 0);
    for(int i = 1; i <= n; ++i){
        ll u = i;
        while(true){
            ll curgcd = get(i, u);
            ll prev = u;
            ll ok = log2(height[u] + 1);
            for(int j = ok; j >= 0 ; --j){
                if(curgcd == get(i, up[u][j])) u = up[u][j];
            }
            res = (res + 1LL * (height[prev] - height[u] + 1) * curgcd % mod) % mod;
            if(u == 1)  break;
            u = up[u][0];
        }
    }
    cout << res;
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro


//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const ll inf = 1e18;
const int LOG = 18;
const int mod = 1e9 + 7;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

vector<ll> v[N];

ll timer;
ll height[N];
ll up[N][LOG];
ll gg[N][LOG];
ll in[N], out[N];

void Dfs(ll node, ll Par, ll cur){
    in[node] = ++timer;
    height[node] = cur;
    up[node][0] = Par;
    if(node == 1)   gg[node][0] = a[node];
    else    gg[node][0] = __gcd(a[node], a[Par]);
    for(int i = 1; i < LOG; ++i){
        up[node][i] = up[up[node][i - 1]][i - 1];
        gg[node][i] = __gcd(gg[up[node][i - 1]][i - 1], gg[node][i - 1]);
    }

    for(auto i: v[node]){
        if(i != Par) Dfs(i, node, cur + 1);
    }
    out[node] = ++timer;
}

bool isAncest(ll u, ll v){ //pahla wala ancestor h dusre wale ka??
    return in[u] <= in[v] && out[v] <= out[u];
}

ll get(ll u, ll v){
    ll j = (int)log2(height[u] - height[v] + 1);
    ll ans =  a[u];
    for(int i = j; i >= 0; --i){
        if(isAncest(v, up[u][i])){
            ans = __gcd(ans, gg[u][i]);
            u = up[u][i];
        }
    }
    return ans;
}

void solve(){
    ll n, x, y;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; ++i){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    Dfs(1, 1, 0);
    for(int i = 1; i <= n; ++i){
        ll u = i, prevgcd = 0;
        while(true){
            ll curgcd = __gcd(prevgcd, a[u]);// get(i, u);
            ll prev = u;
            ll ok = log2(height[u] + 1);
            for(int j = ok; j >= 0 ; --j){
                if(curgcd == __gcd(prevgcd, get(prev, up[u][j]))) u = up[u][j];
            }
            res = (res + 1LL * (height[prev] - height[u] + 1) * curgcd % mod) % mod;
            if(u == 1)  break;
            prevgcd = curgcd;
            u = up[u][0];
        }
    }
    cout << res;
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro


//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const ll inf = 1e18;
const int LOG = 18;
const int mod = 1e9 + 7;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

vector<ll> v[N];

ll timer;
ll height[N];
ll up[N][LOG];
ll gg[N][LOG];
ll in[N], out[N];

void Dfs(ll node, ll Par, ll cur){
    in[node] = ++timer;
    height[node] = cur;
    up[node][0] = Par;
    if(node == 1)   gg[node][0] = a[node];
    else    gg[node][0] = __gcd(a[node], a[Par]);
    for(int i = 1; i < LOG; ++i){
        up[node][i] = up[up[node][i - 1]][i - 1];
        gg[node][i] = __gcd(gg[up[node][i - 1]][i - 1], gg[node][i - 1]);
    }

    for(auto i: v[node]){
        if(i != Par) Dfs(i, node, cur + 1);
    }
    out[node] = ++timer;
}

bool isAncest(ll u, ll v){ //pahla wala ancestor h dusre wale ka??
    return in[u] <= in[v] && out[v] <= out[u];
}

ll get(ll u, ll v){
    ll j = (int)log2(height[u] - height[v] + 1);
    ll ans =  a[u];
    for(int i = j; i >= 0; --i){
        if(isAncest(v, up[u][i])){
            ans = __gcd(ans, gg[u][i]);
            u = up[u][i];
        }
    }
    return ans;
}

void solve(){
    ll n, x, y;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; ++i){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    Dfs(1, 1, 0);
    for(int i = 1; i <= n; ++i){
        ll u = i;
        while(true){
            ll curgcd = get(i, u);
            ll prev = u;
            for(int j = LOG - 1; j >= 0 ; --j){
                if(curgcd == get(i, up[u][j])) u = up[u][j];
            }
            res = (res + 1LL * (height[prev] - height[u] + 1) * curgcd % mod) % mod;
            if(u == 1)  break;
            u = up[u][0];
        }
    }
    cout << res;
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro


//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const ll inf = 1e18;
const int LOG = 18;
const int mod = 1e9 + 7;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

vector<ll> v[N];

ll timer;
ll height[N];
ll up[N][LOG];
ll gg[N][LOG];
ll in[N], out[N];

void Dfs(ll node, ll Par, ll cur){
    in[node] = ++timer;
    height[node] = cur;
    up[node][0] = Par;
    if(node == 1)   gg[node][0] = a[node];
    else    gg[node][0] = __gcd(a[node], a[Par]);
    for(int i = 1; i < LOG; ++i){
        up[node][i] = up[up[node][i - 1]][i - 1];
        gg[node][i] = __gcd(gg[up[node][i - 1]][i - 1], gg[node][i - 1]);
    }

    for(auto i: v[node]){
        if(i != Par) Dfs(i, node, cur + 1);
    }
    out[node] = ++timer;
}

bool isAncest(ll u, ll v){ //pahla wala ancestor h dusre wale ka??
    return in[u] <= in[v] && out[v] <= out[u];
}

void solve(){
    ll n, x, y;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; ++i){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    Dfs(1, 1, 0);
    for(int i = 1; i <= n; ++i){
        ll u = i, prevgcd = 0;
        while(true){
            ll curgcd = __gcd(prevgcd, a[u]);
            ll prev = u;
            for(int j = LOG - 1; j >= 0 ; --j){
                if(curgcd == __gcd(prevgcd, gg[u][j])) u = up[u][j];
            }
            res = (res + 1LL * (height[prev] - height[u] + 1) * curgcd % mod) % mod;
            if(u == 1)  break;
            prevgcd = curgcd;
            u = up[u][0];
        }
    }
    cout << res;
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro


//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const ll inf = 1e18;
const int LOG = 18;
const int mod = 1e9 + 7;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

vector<ll> v[N];

ll timer;
ll height[N];
ll up[N][LOG];
ll gg[N][LOG];
ll in[N], out[N];

void Dfs(ll node, ll Par, ll cur){
    in[node] = ++timer;
    height[node] = cur;
    up[node][0] = Par;
    if(node == 1)   gg[node][0] = a[node];
    else    gg[node][0] = __gcd(a[node], a[Par]);
    for(int i = 1; i < LOG; ++i){
        up[node][i] = up[up[node][i - 1]][i - 1];
        gg[node][i] = __gcd(gg[up[node][i - 1]][i - 1], gg[node][i - 1]);
    }

    for(auto i: v[node]){
        if(i != Par) Dfs(i, node, cur + 1);
    }
    out[node] = ++timer;
}

bool isAncest(ll u, ll v){ //pahla wala ancestor h dusre wale ka??
    return in[u] <= in[v] && out[v] <= out[u];
}

ll get(ll u, ll v){
    ll j = (int)log2(height[u] - height[v] + 1);
    ll ans =  a[u];
    for(int i = j; i >= 0; --i){
        if(isAncest(v, up[u][i])){
            ans = __gcd(ans, gg[u][i]);
            u = up[u][i];
        }
    }
    return ans;
}

void solve(){
    ll n, x, y;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; ++i){
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    Dfs(1, 1, 0);
    for(int i = 1; i <= n; ++i){
        ll u = i, prevgcd = 0;
        while(true){
            ll curgcd = get(i, u);
            ll prev = u;
            ll ok = log2(height[u] + 1);
            for(int j = ok; j >= 0 ; --j){
                if(curgcd == __gcd(prevgcd, get(prev, up[u][j]))) u = up[u][j];
            }
            res = (res + 1LL * (height[prev] - height[u] + 1) * curgcd % mod) % mod;
            if(u == 1)  break;
            prevgcd = curgcd;
            u = up[u][0];
        }
    }
    cout << res;
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
map<ll, ll> *cnt[N];
vector<int> g[N];
ll val[N];
int sol[N];
int sz[N];
int ans = 0;

int add(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a + b) % mod;
}

int mul(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a * b) % mod;
}

void getsz(int v, int p){
    sz[v] = 1;
    for(auto u : g[v])
        if(u != p){
            getsz(u, v);
            sz[v] += sz[u];
        }
}

void dfs(int node, int parent)
{
    if(val[node] == 0)
    {
        int mx = -1, bigChild = -1;
        for(auto u : g[node])
            if(u != parent){
                dfs(u, node);
                if(sz[u] > mx)
                    mx = sz[u], bigChild = u;
                sol[node] = add(sol[node], sol[u]);
            }
        if(bigChild != -1)
            cnt[node] = cnt[bigChild];
        else
            cnt[node] = new map<ll, ll> ();
        (*cnt[node])[val[node]] ++;
        for(auto u : g[node])
            if(u != parent && u != bigChild){
                for(auto x : *cnt[u])
                    (*cnt[node])[x.first] += x.second;
                delete cnt[u];
            }
    }
    else
    {
        cnt[node] = new map<ll, ll>();
        for(auto u : g[node])
            if(u != parent){
                dfs(u, node);
                for(auto &x: *cnt[u])
                {
                    (*cnt[node])[__gcd(val[node], x.first)] += x.second;
                }
                delete cnt[u];
            }
        (*cnt[node])[val[node]]++;
        for(auto &x: *cnt[node])
            sol[node] = add(sol[node], mul(x.first == 0? val[node] : x.first, x.second));
    }
    ans = add(ans, sol[node]);
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    for(int i = 1; i <= n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    getsz(1, 1);
    dfs(1, 1);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
map<ll, int> *cnt[N];
vector<int> g[N];
ll val[N];
int sol[N];
int sz[N];
int ans = 0;

int add(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a + b) % mod;
}

int mul(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a * b) % mod;
}

void getsz(int v, int p){
    sz[v] = 1;
    for(auto u : g[v])
        if(u != p){
            getsz(u, v);
            sz[v] += sz[u];
        }
}

void dfs(int node, int parent)
{
    if(val[node] == 0)
    {
        int mx = -1, bigChild = -1;
        for(auto u : g[node])
            if(u != parent){
                dfs(u, node);
                if(sz[u] > mx)
                    mx = sz[u], bigChild = u;
                sol[node] = add(sol[node], sol[u]);
            }
        if(bigChild != -1)
            cnt[node] = cnt[bigChild];
        else
            cnt[node] = new map<ll, int> ();
        (*cnt[node])[val[node]] ++;
        for(auto u : g[node])
            if(u != parent && u != bigChild){
                for(auto x : *cnt[u])
                    (*cnt[node])[x.first] += x.second;
                delete cnt[u];
            }
    }
    else
    {
        int mx = -1, bigChild = -1;
        for(auto u : g[node])
            if(u != parent){
                dfs(u, node);
                if(sz[u] > mx)
                    mx = sz[u], bigChild = u;
            }
        if(bigChild != -1)
            cnt[node] = cnt[bigChild];
        else
            cnt[node] = new map<ll, int> ();
        (*cnt[node])[val[node]] ++;
        for(auto u : g[node])
            if(u != parent && u != bigChild){
                for(auto x : *cnt[u])
                    (*cnt[node])[x.first] += x.second;
                delete cnt[u];
            }
        map<ll, ll> mp;
        for(auto &x: *cnt[node])
            mp[__gcd(x.first, val[node])] += x.second;
        (*cnt[node]).clear();
        for(auto &x: mp)
            (*cnt[node])[x.first] = x.second;
        for(auto &x: *cnt[node])
            sol[node] = add(sol[node], mul(x.first == 0? val[node] : x.first, x.second));
    }
    ans = add(ans, sol[node]);
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    for(int i = 1; i <= n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    getsz(1, 1);
    dfs(1, 1);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
vector<int> g[N];
ll val[N];
map<ll, int> mp;
int ans = 0;

int add(int a, int b)
{
    return (a + b) % mod;
}

int mul(ll a, int b)
{
    a %= mod;
    return (a * b) % mod;
}

void dfs(int node, int parent)
{
    map<ll, int> prev_mp = mp;
    mp.clear();
    for(auto &x: prev_mp)
        mp[__gcd(val[node], x.first)] += x.second;
    mp[val[node]]++;
    for(auto &x: mp)
        ans = add(ans, mul(x.first == 0 ? val[node] : x.first, x.second));
    for(auto &new_node: g[node])
    {
        if(new_node != parent)
            dfs(new_node, node);
    }
    mp = prev_mp;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    for(int i = 1; i <= n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 1);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
vector<int> g[N];
ll val[N];
map<ll, int> mp;
int ans = 0;

int add(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a + b) % mod;
}

int mul(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a * b) % mod;
}

void dfs(int node, int parent)
{
    map<ll, int> prev_mp = mp;
    mp.clear();
    for(auto &x: prev_mp)
        mp[__gcd(val[node], x.first)] += x.second;
    mp[val[node]]++;
    for(auto &x: mp)
        ans = add(ans, mul(x.first == 0 ? val[node] : x.first, x.second));
    for(auto &new_node: g[node])
    {
        if(new_node != parent)
            dfs(new_node, node);
    }
    mp = prev_mp;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    for(int i = 1; i <= n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 1);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
map<ll, ll> *cnt[N];
vector<int> g[N];
ll val[N];
int sol[N];
int sz[N];
int ans = 0;

int add(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a + b) % mod;
}

int mul(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a * b) % mod;
}

void getsz(int v, int p){
    sz[v] = 1;
    for(auto u : g[v])
        if(u != p){
            getsz(u, v);
            sz[v] += sz[u];
        }
}

void dfs(int node, int parent)
{
    if(val[node] == 0)
    {
        int mx = -1, bigChild = -1;
        for(auto u : g[node])
            if(u != parent){
                dfs(u, node);
                if(sz[u] > mx)
                    mx = sz[u], bigChild = u;
                sol[node] = add(sol[node], sol[u]);
            }
        if(bigChild != -1)
            cnt[node] = cnt[bigChild];
        else
            cnt[node] = new map<ll, ll> ();
        (*cnt[node])[val[node]] ++;
        for(auto u : g[node])
            if(u != parent && u != bigChild){
                for(auto x : *cnt[u])
                    (*cnt[node])[x.first] += x.second;
            }
    }
    else
    {
        cnt[node] = new map<ll, ll>();
        for(auto u : g[node])
            if(u != parent){
                dfs(u, node);
                for(auto &x: *cnt[u])
                {
                    (*cnt[node])[__gcd(val[node], x.first)] += x.second;
                }
            }
        (*cnt[node])[val[node]]++;
        for(auto &x: *cnt[node])
            sol[node] = add(sol[node], mul(x.first == 0? val[node] : x.first, x.second));
    }
    ans = add(ans, sol[node]);
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    for(int i = 1; i <= n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    getsz(1, 1);
    dfs(1, 1);
    cout << ans;
    return 0;
}