#include<bits/stdc++.h>
#define f(i,a,b) for( int i=a;i<=b;++i)
#define ff(i,a,b) for( int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const double eps = 1e-6;
const int N = 1e5 + 5;
vector<pair<ll,int> > d[N];//到每个点的上一层路径的gcd
vector<int> G[N];
ll a[N];
ll ans = 0;
void dfs(int u, int fa)
{
	unordered_map<ll, int> mp;
	mp[a[u]]++;
	ans += a[u];ans %= mod;
	for (auto j : d[u])
	{
		ll nx_gcd = gcd(j.first, a[u]);
		mp[nx_gcd] += j.second;
		ans += (ll)nx_gcd%mod * j.second%mod;
		ans %= mod;
	}
	for (auto i : G[u])
	{
		if (i == fa)continue;
		for (auto I : mp)
		{
			d[i].emplace_back(pair<ll,int>{ I.first,I.second });
		}
		dfs(i, u);
	}
}
int main()
{
	//freopen("in.txt", "r", stdin);
	int n = in();
	f(i, 1, n)scanf("%lld", &a[i]);
	f(i, 1, n - 1)
	{
		int x = in();
		int y = in();
		G[x].emplace_back(y);
		G[y].emplace_back(x);
	}
	dfs(1, -1);
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
const ll mod = 1e9+7;
vector<vi> graph;
vector<ll> a;
int n;
const int N = 100001;
map<ll,int> cnt[N];
map<ll,int>::iterator p,q;
ll ans = 0ll;
void dfs(int start,int pa)
{
	int i,j,k;
	if(pa!=-1)
	{
		for(q=cnt[pa].begin();q!=cnt[pa].end();q++)
		{
			cnt[start][__gcd(a[start],q->first)] += q->second;
		}
	}
	cnt[start][a[start]]++;
	for(q=cnt[start].begin();q!=cnt[start].end();++q)
	{
		ans = (ans + 1ll*q->first*q->second%mod)%mod;
	}
	for(i=0;i<graph[start].size();++i)
	{
		j = graph[start][i];
		if(j!=pa)
		{
			dfs(j,start);
		}
	}
}
int main()
{
	int i,x,y;
	scanf("%d",&n);
	a.assign(n+1,0ll);
	graph.assign(n+1,vi());
	for(i=1;i<=n;++i)	scanf("%lld",&a[i]);
	for(i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	dfs(1,-1);
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
const ll mod = 1e9+7;
vector<vi> graph;
vector<ll> a;
int n;
const int N = 100001;
map<ll,int> cnt[N];
map<ll,int>::iterator p,q;
void dfs(int start,int pa)
{
	int i,j,k;
	for(i=0;i<graph[start].size();++i)
	{
		j = graph[start][i];
		if(pa!=j)
		{
			dfs(j,start);
			for(q=cnt[j].begin();q!=cnt[j].end();q++)
			{
				cnt[start][__gcd(a[start],q->first)] += q->second;
			}
		}
	}
	cnt[start][a[start]]++;
}
int main()
{
	int i,x,y;
	scanf("%d",&n);
	a.assign(n+1,0ll);
	graph.assign(n+1,vi());
	for(i=1;i<=n;++i)	scanf("%lld",&a[i]);
	for(i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	dfs(1,-1);
	ll ans = 0ll;
	for(i=1;i<=n;++i)
	{
		for(p=cnt[i].begin();p!=cnt[i].end();++p)
		{
			ans = (ans + 1ll*p->first * p->second%mod )%mod;
		}
	}
	cout<<ans;
}


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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo; const int N = 100005;
#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#endif

const ll M = 1e9 + 7;

ll B[N];

vector<vi> g;
ll ans;

map<ll, ll> dfs(int u, int p) {
    map<ll, ll> res;
    res[B[u]]++;
    for (int v : g[u]) if (v != p) {
        auto m = dfs(v, u);
        for (auto& p : m) {
            res[__gcd(p.first, B[u])] += p.second;
        }
    }
    for (auto& p : res) {
        ans += p.second * p.first % M;
        ans %= M;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;

    rep(i, 1, n+1)
        cin >> B[i];

    g.resize(n+1);
    fo1(i, n-1) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    dfs(1, 0);

    cout << ans << endl;

    return 0;
}


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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo; const int N = 100005;
#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#endif

constexpr ll M = 1e9 + 7;

ll B[N];

vector<vi> g;
vi leafs;
int P[N];
ll ans;

map<ll, ll> ress[N];

void dfs(int u) {
    if (sz(ress[u]) > 0) return;

    auto& res = ress[u];
    res[B[u]]++;

    if (P[u] != 0) {
        dfs(P[u]);
        for (auto& p : ress[P[u]]) {
            const ll gcd = __gcd(p.first, B[u]);
            res[gcd] += p.second;
        }
    }
    for (auto& p : res) {
        ans += p.first * p.second % M;
        ans %= M;
    }
}

void findParent(int u, int p) {
    P[u] = p;
    for (int v : g[u]) if (v != p) {
        findParent(v, u);
    }

    if (sz(g[u]) == 1) {
        leafs.emplace_back(u);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;

    rep(i, 1, n+1) {
        cin >> B[i];
    }

    g.resize(n+1);
    fo1(i, n-1) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    findParent(1, 0);

    for (int leaf : leafs)
        dfs(leaf);

    cout << ans << endl;

    return 0;
}


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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo; const int N = 100005;
#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#endif

const ll M = 1e9 + 7;

ll B[N];

vector<vi> g;
ll ans;

map<ll, ll> dfs(int u, int p) {
    map<ll, ll> res;
    res[B[u]]++;
    for (int v : g[u]) if (v != p) {
        auto m = dfs(v, u);
        for (auto& p : m) {
            res[__gcd(p.first, B[u])] += p.second;
        }
    }
    for (auto& p : res) {
        ans += p.second * p.first % M;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;

    rep(i, 1, n+1)
        cin >> B[i];

    g.resize(n+1);
    fo1(i, n-1) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    dfs(1, 0);

    cout << ans << endl;

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:2750050000")
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<sstream>
#include<numeric>
#include<random>
#include<functional>
#include<unordered_set>
#include<unordered_map>
#include<stack>

using namespace std;

typedef unsigned int ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pdd;
typedef pair<int, char> pic;
typedef pair<pii, ll> piii;
#define xx first
#define yy second
#define zz second.second
#define mp make_pair
#define y1 oshfkfsldhs
#define union jfghjdghdjhgjhdjgh
#define all(x) (x).begin(), (x).end()

const ll MOD = 1e9 + 7;
const ll MOD1 = 7340033;
const ll BAS = 257;
const ll dy[] = { -1, -1, 1, 1 };
const ll dx[] = { -1, 1, -1, 1 };
const ll N = 1.5e8;
const double EPS = 1e-11;
const long double PI = 3.14159265358979323846;
const ll SZ = 700;
const ll INF = 1e18 + 213;
const ll MAXN = 5e5 + 10;

#ifdef _DEBUG
int __builtin_popcount(int x)
{
	int cnt = 0;
	while (x)
		cnt += x & 1, x >>= 1;
	return cnt;
}
#endif

ll gcd(ll x, ll y)
{
	if (x == -1)
		return y;
	if (y == -1)
		return x;
	if (x == 0)
		return y;
	return gcd(y % x, x);
}

ll n, m, k, a[MAXN], b[MAXN];
ll t[MAXN];

void upd(int v, int tl, int tr, int pos, ll x)
{
	if (tl == tr)
	{
		t[v] = x;
	}
	else
	{
		int tm = tl + tr >> 1;
		if (pos <= tm)
			upd(2 * v + 1, tl, tm, pos, x);
		else
			upd(2 * v + 2, tm + 1, tr, pos, x);
		t[v] = gcd(t[2 * v + 1], t[2 * v + 2]);
	}
}

ll ask(int v, int tl, int tr, int le, int ri)
{
	if (tl > ri || tr < le)
		return -1;
	if (tl >= le && tr <= ri)
		return t[v];
	int tm = tl + tr >> 1;
	return gcd(ask(2 * v + 1, tl, tm, le, ri),
		ask(2 * v + 2, tm + 1, tr, le, ri));
}

ll answer = 0;
vector<int> g[MAXN];
bool us[MAXN];
int iter = 0;
ll x[MAXN];

void dfs(int v)
{
	us[v] = 1;
	upd(0, 0, n - 1, iter, x[v]);
	int le = 0, ri = iter;
	while (ri >= 0)
	{
		int bl = -1, br = ri;
		ll cur = ask(0, 0, n - 1, br, iter);
		while (br - bl > 1)
		{
			int mi = br + bl >> 1;
			ll w = ask(0, 0, n - 1, mi, iter);
			if (w == cur)
			{
				br = mi;
			}
			else
				bl = mi;
		}
		answer += (ri - br + 1) * cur % MOD;
		answer %= MOD;
		ri = br - 1;
	}
	iter++;
	for (int to : g[v])
		if (!us[to])
			dfs(to);
	iter--;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(10);
	srand(89398);
#ifdef _DEBUG
	auto _ = freopen("input.txt", "r", stdin);
	_ = freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0);
	cout << answer % MOD;

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:2750050000")
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<sstream>
#include<numeric>
#include<random>
#include<functional>
#include<unordered_set>
#include<unordered_map>
#include<stack>

using namespace std;

typedef unsigned int ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pdd;
typedef pair<int, char> pic;
typedef pair<pii, ll> piii;
#define xx first
#define yy second
#define zz second.second
#define mp make_pair
#define y1 oshfkfsldhs
#define union jfghjdghdjhgjhdjgh
#define all(x) (x).begin(), (x).end()

const ll MOD = 1e9 + 7;
const ll MOD1 = 7340033;
const ll BAS = 257;
const ll dy[] = { -1, -1, 1, 1 };
const ll dx[] = { -1, 1, -1, 1 };
const ll N = 1.5e8;
const double EPS = 1e-11;
const long double PI = 3.14159265358979323846;
const ll SZ = 700;
const ll INF = 1e18 + 213;
const ll MAXN = 5e5 + 10;

#ifdef _DEBUG
int __builtin_popcount(int x)
{
	int cnt = 0;
	while (x)
		cnt += x & 1, x >>= 1;
	return cnt;
}
#endif

ll gcd(ll x, ll y)
{
	if (x == -1)
		return y;
	if (y == -1)
		return x;
	if (x == 0)
		return y;
	return gcd(y % x, x);
}

ll n, m, k, a[MAXN], b[MAXN];
ll t[MAXN];

void upd(int v, int tl, int tr, int pos, ll x)
{
	if (tl == tr)
	{
		t[v] = x;
	}
	else
	{
		int tm = tl + tr >> 1;
		if (pos <= tm)
			upd(2 * v + 1, tl, tm, pos, x);
		else
			upd(2 * v + 2, tm + 1, tr, pos, x);
		t[v] = gcd(t[2 * v + 1], t[2 * v + 2]);
	}
}

ll ask(int v, int tl, int tr, int le, int ri)
{
	if (tl > ri || tr < le)
		return -1;
	if (tl >= le && tr <= ri)
		return t[v];
	int tm = tl + tr >> 1;
	return gcd(ask(2 * v + 1, tl, tm, le, ri),
		ask(2 * v + 2, tm + 1, tr, le, ri));
}

ll deep(int v, int tl, int tr, ll X)
{
	if(tl == tr)
	{
		return tl;
	}
	int tm = tl + tr >> 1;
	if (gcd(t[2 * v + 2], X) == X)
		return(deep(2 * v + 1, tl, tm, X));
	else
		return deep(2 * v + 2, tm + 1, tr, X);
}

ll answer = 0;
vector<int> g[MAXN];
bool us[MAXN];
int iter = 0;
ll x[MAXN];

void dfs(int v)
{
	us[v] = 1;
	upd(0, 0, n - 1, iter, x[v]);
	int le = 0, ri = iter;
	while (ri >= 0)
	{
		int bl = -1, br = ri;
		ll cur = ask(0, 0, n - 1, br, iter);
		br = deep(0, 0, n - 1, cur);
		ll w = ask(0, 0, n - 1, br, iter);
		if (w != cur)
			br++;
		answer += (ri - br + 1) * cur % MOD;
		//cout << v << " " << br << " " << ri << " " << answer << " " << cur << "\n";
		ri = br - 1;
	}
	iter++;
	for (int to : g[v])
		if (!us[to])
			dfs(to);
	iter--;
	upd(0, 0, n - 1, iter, -1);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(10);
	srand(89398);
#ifdef _DEBUG
	auto _ = freopen("input.txt", "r", stdin);
	_ = freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0);
	cout << answer % MOD;

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:2750050000")
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<sstream>
#include<numeric>
#include<random>
#include<functional>
#include<unordered_set>
#include<unordered_map>
#include<stack>

using namespace std;

typedef unsigned int ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pdd;
typedef pair<int, char> pic;
typedef pair<pii, ll> piii;
#define xx first
#define yy second
#define zz second.second
#define mp make_pair
#define y1 oshfkfsldhs
#define union jfghjdghdjhgjhdjgh
#define all(x) (x).begin(), (x).end()

const ll MOD = 998244353;
const ll MOD1 = 7340033;
const ll BAS = 257;
const ll dy[] = { -1, -1, 1, 1 };
const ll dx[] = { -1, 1, -1, 1 };
const ll N = 1.5e8;
const double EPS = 1e-11;
const long double PI = 3.14159265358979323846;
const ll SZ = 700;
const ll INF = 1e18 + 213;
const ll MAXN = 5e5 + 10;

#ifdef _DEBUG
int __builtin_popcount(int x)
{
	int cnt = 0;
	while (x)
		cnt += x & 1, x >>= 1;
	return cnt;
}
#endif

ll gcd(ll x, ll y)
{
	if (x == -1)
		return y;
	if (y == -1)
		return x;
	if (x == 0)
		return y;
	return gcd(y % x, x);
}

ll n, m, k, a[MAXN], b[MAXN];
ll t[MAXN];

void upd(int v, int tl, int tr, int pos, ll x)
{
	if (tl == tr)
	{
		t[v] = x;
	}
	else
	{
		int tm = tl + tr >> 1;
		if (pos <= tm)
			upd(2 * v + 1, tl, tm, pos, x);
		else
			upd(2 * v + 2, tm + 1, tr, pos, x);
		t[v] = gcd(t[2 * v + 1], t[2 * v + 2]);
	}
}

ll ask(int v, int tl, int tr, int le, int ri)
{
	if (tl > ri || tr < le)
		return -1;
	if (tl >= le && tr <= ri)
		return t[v];
	int tm = tl + tr >> 1;
	return gcd(ask(2 * v + 1, tl, tm, le, ri),
		ask(2 * v + 2, tm + 1, tr, le, ri));
}

ll answer = 0;
vector<int> g[MAXN];
bool us[MAXN];
int iter = 0;
ll x[MAXN];

void dfs(int v)
{
	us[v] = 1;
	upd(0, 0, n - 1, iter, x[v]);
	int le = 0, ri = iter;
	while (ri >= 0)
	{
		int bl = -1, br = ri;
		ll cur = ask(0, 0, n - 1, br, iter);
		while (br - bl > 1)
		{
			int mi = br + bl >> 1;
			ll w = ask(0, 0, n - 1, mi, iter);
			if (w == cur)
			{
				br = mi;
			}
			else
				bl = mi;
		}
		answer += (ri - br + 1) * cur;
		ri = br - 1;
	}
	iter++;
	for (int to : g[v])
		if (!us[to])
			dfs(to);
	iter--;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(10);
	srand(89398);
#ifdef _DEBUG
	auto _ = freopen("input.txt", "r", stdin);
	_ = freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0);
	cout << answer;

}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 1;
const int MOD = 1e9 + 7;

ll n, x[N], ans = 0;
list<int> graph[N];

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

int add(int a, int b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

map<ll, int> gcds;
void dfs(int v, int p = -1) {
    map<ll, int> temp;
    temp[x[v]] = 1;
    for (auto i : gcds) {
        ll g = gcd(x[v], i.first);
        temp[g] = add(temp[g], i.second);
    }
    for (auto i : temp)
        ans = add(ans, mul(i.first % MOD, i.second));

    swap(gcds, temp);
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
    }
    swap(gcds, temp);
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 3;
const ll MOD = 1e9 + 7;

ll n, x[N];
map<int, ll> cnt[N];
vector<int> graph[N];

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

void dfs(int v, int p = -1) {
    cnt[v][x[v]]++;
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        // log ?
        for (auto a : cnt[to]) {
            cnt[v][gcd(x[v], a.first)] += a.second;
        }
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto p : cnt[i]) {
            ans += 1LL * p.first * p.second % MOD;
        }
        ans %= MOD;
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 2;
const int MOD = 1e9 + 7;

ll n, x[N], ans = 0;
vector<pair<ll, int>> cnt[N];
list<int> graph[N];

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

int add(int a, int b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

void dfs(int v, int p = -1) {
    vector<pair<ll, int>> temp;
    temp.emplace_back(x[v], 1);
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        for (auto a : cnt[to]) {
            ll g = gcd(x[v], a.first);
            temp.emplace_back(g, a.second);
        }
        cnt[to].clear();
    }

    sort(temp.begin(), temp.end());
    cnt[v].push_back(temp[0]);
    for (int i = 1; i < temp.size(); ++i) {
        if (temp[i].first == temp[i - 1].first) {
            cnt[v].back().second = add(cnt[v].back().second, temp[i].second);
        }
        else {
            cnt[v].push_back(temp[i]);
        }
    }

    for (int i = 0; i < cnt[v].size(); ++i) {
        ans = add(ans, mul(cnt[v][i].first % (ll)MOD, cnt[v][i].second));
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

//    for (int i = 0; i < n; ++i) {
//        for (auto p : cnt[i]) {
//            ans = add(ans, mul(p.first % (ll)MOD, p.second));
//        }
//    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 3;

ll n, x[N];
map<int, ll> cnt[N];
vector<int> graph[N];

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

void dfs(int v, int p = -1) {
    cnt[v][x[v]]++;
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        // log ?
        for (auto a : cnt[to]) {
            cnt[v][gcd(x[v], a.first)] += a.second;
        }
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto p : cnt[i]) {
            ans += 1LL * p.first * p.second;
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 3;
const int MOD = 1e9 + 7;

ll n, x[N];
map<ll, int> cnt[N];
list<int> graph[N];

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

int add(int a, int b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

void dfs(int v, int p = -1) {
    cnt[v][x[v]] = 1;
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        for (auto a : cnt[to]) {
            ll g = gcd(x[v], a.first);
            cnt[v][g] = add(cnt[v][g], a.second);
        }
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto p : cnt[i]) {
            ans = add(ans, mul(p.first % (ll)MOD, p.second));
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 1;
const int MOD = 1e9 + 7;

ll n, x[N], ans = 0;
map<ll, int> cnt[N];
list<int> graph[N];

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

int add(int a, int b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

void dfs(int v, int p = -1) {
    cnt[v][x[v]] = 1;
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        for (auto a : cnt[to]) {
            ll g = gcd(x[v], a.first);
            cnt[v][g] = add(cnt[v][g], a.second);
        }
        cnt[to].clear();
    }

    for (auto i : cnt[v]) {
        ans = add(ans, mul(i.first % (ll)MOD, i.second));
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 3;
const ll MOD = 1e9 + 7;

ll n, x[N];
map<int, ll> cnt[N];
vector<int> graph[N];

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

void dfs(int v, int p = -1) {
    cnt[v][x[v]]++;
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        // log ?
        for (auto a : cnt[to]) {
            cnt[v][gcd(x[v], a.first)] += a.second;
        }
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto p : cnt[i]) {
            ans = (ans + (1LL * p.first * p.second % MOD)) % MOD;
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 1;
const int MOD = 1e9 + 7;

ll n, x[N], ans = 0;
map<ll, int> cnt[N];
list<int> graph[N];

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

int add(int a, int b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

void dfs(int v, int p = -1) {
    cnt[v][x[v]] = 1;
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        for (auto a : cnt[to]) {
            ll g = gcd(x[v], a.first);
            cnt[v][g] = add(cnt[v][g], a.second);
        }
        cnt[to].clear();
    }

    for (auto i : cnt[v]) {
        ans = add(ans, mul(i.first % (ll)MOD, i.second));
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 3;
const ll MOD = 1e9 + 7;

ll n, x[N];
map<int, ll> cnt[N];
vector<int> graph[N];

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

ll add(ll a, ll b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

ll mul(ll a, ll b) {
    return 1LL * a * b % MOD;
}

ll checkmod(ll a) {
    if (a < MOD)
        return a;
    return a % MOD;
}

void dfs(int v, int p = -1) {
    cnt[v][x[v]] = add(cnt[v][x[v]], 1);
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        for (auto a : cnt[to]) {
            int g = gcd(x[v], a.first);
            cnt[v][g] = add(cnt[v][g], a.second);
        }
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto p : cnt[i]) {
            ans = add(ans, mul(checkmod(p.first), checkmod(p.second)));
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 2;
const int MOD = 1e9 + 7;

ll n, x[N];
vector<pair<ll, int>> cnt[N];
list<int> graph[N];

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

int add(int a, int b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

void dfs(int v, int p = -1) {
    vector<pair<ll, int>> temp;
    temp.emplace_back(x[v], 1);
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
//        for (auto a : cnt[to]) {
//            ll g = gcd(x[v], a.first);
//            cnt[v][g] = add(cnt[v][g], a.second);
//        }
        for (auto a : cnt[to]) {
            ll g = gcd(x[v], a.first);
            temp.emplace_back(g, a.second);
        }
    }

    sort(temp.begin(), temp.end());
    cnt[v].push_back(temp[0]);
    for (int i = 1; i < temp.size(); ++i) {
        if (temp[i].first == temp[i - 1].first) {
            cnt[v].back().second = add(cnt[v].back().second, temp[i].second);
        }
        else {
            cnt[v].push_back(temp[i]);
        }
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto p : cnt[i]) {
            ans = add(ans, mul(p.first % (ll)MOD, p.second));
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 3;
const ll MOD = 1e9 + 7;

ll n, x[N];
map<ll, ll> cnt[N];
vector<int> graph[N];

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

ll add(ll a, ll b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

ll mul(ll a, ll b) {
    return 1LL * a * b % MOD;
}

ll checkmod(ll a) {
    if (a < MOD)
        return a;
    return a % MOD;
}

void dfs(int v, int p = -1) {
    cnt[v][x[v]] = 1;
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        for (auto a : cnt[to]) {
            ll g = gcd(x[v], a.first);
            cnt[v][g] = add(cnt[v][g], a.second);
        }
    }
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto p : cnt[i]) {
            ans = add(ans, mul(checkmod(p.first), checkmod(p.second)));
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 1e5 + 3;
const ll MOD = 1e9 + 7;

ll n, x[N];
map<int, ll> cnt[N];
vector<int> graph[N];

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

void dfs(int v, int p = -1) {
    cnt[v][x[v]]++;
    for (int to : graph[v]) {
        if (to == p) continue;

        dfs(to, v);
        // log ?
        for (auto a : cnt[to]) {
            cnt[v][gcd(x[v], a.first)] += a.second;
        }
    }
}

ll add(ll a, ll b) {
    a += b;
    if (a < 0) a += MOD;
    if (a >= MOD) a -= MOD;
    return a;
}

ll mul(ll a, ll b) {
    return 1LL * a * b % MOD;
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0);

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto p : cnt[i]) {
            ans = add(ans, mul(p.first % MOD, p.second % MOD));
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));

    int t = 1;
//    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=1e9+7;
ll mul(ll a, ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll add(ll a, ll b)
{
	return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a, ll b)
{
	return ((a%mod)-(b%mod)+mod)%mod;
}
ll c[1000005];
vector<ll> v[1000005];
ll out=0;
ll n;
void dfs(ll x, ll p,map<ll,ll> m)
{
	map<ll,ll> f;
	for(auto it=m.begin();it!=m.end();it++)
	{
		f[__gcd(c[x],(it->first))]=(it->second);
		out=add(out,mul(__gcd(c[x],(it->first)),(it->second)));
	}
	f[c[x]]++;
	out=add(out,c[x]);
	for(ll i=0;i<v[x].size();i++)
	{
		if(v[x][i]!=p)
		{
			dfs(v[x][i],x,f);
		}
	}
}

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		cin>>c[i];
	}
	for(ll i=0;i<n-1;i++)
	{
		ll x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	map<ll,ll> m;
	dfs(1,0,m);
	cout<<out;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=1000 * 1000 * 1000 + 7;
ll mul(ll a, ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll add(ll a, ll b)
{
	return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a, ll b)
{
	return ((a%mod)-(b%mod)+mod)%mod;
}
ll c[1000005];
vector<ll> v[1000005];
ll out=0;
ll n;
void dfs(ll x, ll p,map<ll,ll> m)
{
	map<ll,ll> f;
	for(auto it=m.begin();it!=m.end();it++)
	{
		f[__gcd(c[x],(it->first))]=add(f[__gcd(c[x],(it->first))],(it->second));

	}
	f[c[x]]++;

	for(auto it=f.begin();it!=f.end();it++)
	{
		out=add(out,mul((it->first),(it->second)));

	}
	for(ll i=0;i<v[x].size();i++)
	{
		if(v[x][i]!=p)
		{
			dfs(v[x][i],x,f);
		}
	}
}

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		cin>>c[i];

	}
	for(ll i=0;i<n-1;i++)
	{
		ll x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	map<ll,ll> m;
	dfs(1,0,m);
	cout<<out;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5,mod=1e9+7;
vector<ll> adj[N];
ll n,a[N],ans;
void dfs(ll node,ll pr,map<ll,ll> &prv){
    map<ll,ll> mp;mp[a[node]]++;
    for(auto &ele:prv)mp[__gcd(a[node],ele.first)]+=ele.second;
    for(auto &ele:mp)ans+=(ele.first*ele.second)%mod,ans%=mod;
    for(auto &v:adj[node])if(v!=pr)dfs(v,node,mp);
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;for(ll i=1;i<=n;i++)cin>>a[i];
    for(ll i=1,u,v;i<=n-1;i++)cin>>u>>v,adj[u].push_back(v),adj[v].push_back(u);
    map<ll,ll> mp;dfs(1,1,mp);
    cout<<ans;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=1e5+777;
const int mod=1e9+7;

int n;
ll x[mx];
vector<int> adj[mx];

ll eval(map<ll,int> &mp, int cur, int par=0) {
	ll ret=0;
	map<ll,int> mp2;
	for (auto it : mp)
		mp2[__gcd(it.first,x[cur])]+=it.second;
	mp2[x[cur]]++;
	for (auto it : mp2)
		ret=(ret+(it.first*it.second)%mod)%mod;
	for (int nxt : adj[cur])
		if(nxt!=par)
			ret=(ret+eval(mp2,nxt,cur))%mod;
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	cin>>n;
	for (int i=1; i<=n; i++)
		cin>>x[i];
	for (int i=0; i<n-1; i++) {
		int a,b; cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	map<ll,int> mp;
	cout<<eval(mp,1)<<"\n";
	return 0;
}


/***** Raf *****/
///#include <stdio.h>
///#include <iostream>
///#include <cstring>
///#include <cmath>
///#include <algorithm>
///#include <string>
///#include <vector>
///#include <map>
///#include <set>
///#include <queue>
///#include <cstdlib>
///#include <limits>
///#include <iostream>
///#include <sstream>
///#include <unordered_set>
///#include <unordered_map>
///#include <random>
#include <bits/stdc++.h>
///#include <bits/stdtr1c++.h>
///#include <ext/pb_ds/assoc_container.hpp>
///#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
///using namespace __gnu_pbds;

#define              MAX             500005
#define              EPS             1e-9
#define              ull             unsigned long long
#define              ll              long long
#define              inf             INT_MAX
#define              pi              acos(-1.0)
#define              vi              vector<int>
#define              vl              vector<long long>
#define              pii             pair<int,int>
#define              pll             pair<long long,long long>
#define              mp              make_pair
#define              mem(a, v)       memset(a, v, sizeof (a))
#define              mod             1000000007
#define              all(a)          a.begin(),a.end()
#define              rall(a)         a.rbegin(),a.rend()
#define              ff              first
#define              ss              second
#define              arsort(ar,n)    sort(ar,ar+n);
#define              vsort(v)        sort(v.begin(),v.end())
#define              vrev(v)         reverse(v.begin(),v.end())
#define              arrev(ar,n)     reverse(ar,ar+n)
#define              pb              push_back
#define              popb            pop_back
#define              booster()       ios_base::sync_with_stdio(0); cin.tie(0);
#define              read(f)         freopen(f, "r", stdin)
#define              write(f)         freopen(f, "w", stdout)
#define              scani(x)        scanf("%d",&x)
#define              scanl(x)        scanf("%I64d",&x)
#define              scand(x)        scanf("%lf",&x)
#define              scans(x)        scanf("%s",x)
#define              OUT(x)          printf("%d\n",x)
#define              OUTS(x)         printf("%d ",x)
#define              min3(a,b,c)     min(a,min(b,c))
#define              max3(a,b,c)     max(a,max(b,c))
#define              min4(a,b,c,d)   min(min(a,b),min(c,d))
#define              max4(a,b,c,d)   max(max(a,b),max(c,d))
#define              max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define              min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))

#define              bitCheck(a,k)     ((bool)(a&(1<<(k))))
#define              bitOff(a,k)       (a&(~(1<<(k))))
#define              bitOn(a,k)        (a|(1<<(k)))
#define              bitFlip(a,k)      (a^(1<<(k)))

#define              POPCOUNT           __builtin_popcount
#define              POPCOUNTLL         __builtin_popcountll
#define              RIGHttmOST          __builtin_ctzll
#define              LEFttmOST(x)        (63-__builtin_clzll((x)))

#define scani2(a,b) scani(a) , scani(b)
#define scani3(a,b,c) scani(a), scani(b), scani(c)
#define scani4(a,b,c,d) scani(a), scani(b), scani(c), scani(d)
#define scani5(a,b,c,d,e) scani(a), scani(b), scani(c), scani(d) , scani(e)
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*********************Ordered Multiset*************************/

/*** Needs C++11 or C++14 ***/
/// Treap supporting duplicating values in set
/// Maximum value of treap * ADD must fit in long long

/*

struct Treap{ /// hash = 96814
    int len;
    const int ADD = 1000010;
    const int MAXVAL = 1000000010;
    tr1::unordered_map <long long, int> mp; /// Change to int if only int in treap
    tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> T;
    Treap(){
        len = 0;
        T.clear(), mp.clear();
    }
    inline void clear(){
        len = 0;
        T.clear(), mp.clear();
    }
    inline void insert(long long x){
        len++, x += MAXVAL;
        int c = mp[x]++;
        T.insert((x * ADD) + c);
    }
    inline void erase(long long x){
        x += MAXVAL;
        int c = mp[x];
        if (c){
            c--, mp[x]--, len--;
            T.erase((x * ADD) + c);
        }
    }
    /// 1-based index, returns the K'th element in the treap, -1 if none exists
    inline long long kth(int k){
        if (k < 1 || k > len) return -1;
        auto it = T.find_by_order(--k);
        return ((*it) / ADD) - MAXVAL;
    }
    /// Count of value < x in treap
    inline int count(long long x){
        x += MAXVAL;
        int c = mp[--x];
        return (T.order_of_key((x * ADD) + c));
    }
    /// Number of elements in treap
    inline int size(){
        return len;
    }
};

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;///*X.find_by_order();X.order_of_key();
template <class T> inline bool isLeap(T y) {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }*/
template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
template <class T> inline T BigMod(T Base,T power,T M=mod){if(power==0)return 1;if(power&1)return ((Base%M)*(BigMod(Base,power-1,M)%M))%M;
else{T y=BigMod(Base,power/2,M)%M;return (y*y)%M;}}
template <class T> inline T ModInv (T A,T M = mod){return BigMod(A,M-2,M);}

int fx[] = {-1,+0,+1,+0,+1,+1,-1,-1,+0};
int fy[] = {+0,-1,+0,+1,+1,-1,+1,-1,+0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

/*********************** let the play begin() ***********************************/

vi edge[MAX];ll val[MAX];set<ll>ss;unordered_map<ll,ll>un;

ll dfs(int s,int p  = 0){

    ll ans = 0;
    vector<pll>v;
    v.pb(pll(1,val[s]));
    for(auto it : ss){
        ll x = __gcd(val[s],it);
        v.pb(pll(un[it],x));
    }
    set<ll>temp  = ss;
    ss.clear();
    unordered_map<ll,ll>un2 = un;
    un.clear();
    for(auto it : v){
        ss.insert(it.ss);
        un[it.ss] += it.ff;
        ans += it.ss * it.ff;
        if(ans>=mod)ans %= mod;
    }
    for(auto it : edge[s]){
        if(it==p)continue;
        ans += dfs(it,s);
        if(ans >= mod) ans %= mod;
    }
    un = un2;
    ss = temp;
    return ans;
}

int main()
{
    booster()
    //read("input.txt");
    int n;
    cin >> n;
    for(int i = 1;i<=n;i++){
        cin >> val[i];
    }
    for(int i = 1;i<n;i++){
        int a,b;
        cin >> a >> b;
        edge[a].pb(b);
        edge[b].pb(a);
    }
    cout << dfs(1) << endl;
    return 0;
}


/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
/*
    Use only when the modular is fixed;
    Computing inverse takes logN time so see whether to store it in a array;
*/
template <int mod = MOD>
struct Modular {
    int value;
    Modular(long long v = 0) {if(v >= MOD || v < -MOD) v %= MOD;value = v; if (value < 0) value += mod;}
    Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}

    Modular& operator+=(Modular const& b) {value += b.value; if (value >= mod) value -= mod; return *this;}
    Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += mod;return *this;}
    Modular& operator*=(Modular const& b) {long long res = (long long)value * b.value;if(res >= MOD){res %= MOD;}value = res;return *this;}

    friend Modular mexp(Modular a, long long e) {
        e %= (mod - 1);
        Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
        return res;
    }
    friend Modular inverse(Modular a) { return mexp(a, mod - 2); }

    Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
    friend Modular operator+(Modular a, Modular const b) { return a += b; }
    friend Modular operator-(Modular a, Modular const b) { return a -= b; }
    friend Modular operator-(Modular const a) { return 0 - a; }
    friend Modular operator*(Modular a, Modular const b) { return a *= b; }
    friend Modular operator/(Modular a, Modular const b) { return a /= b; }
    friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
    friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
    friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};

using Mint = Modular<>;
Mint ans = 0;
vl arr;
vvi adj;
vector<map<ll, int>> dp;

void dfs(int v = 0, int p = 0) {
    trav(elem, dp[p]) {
        dp[v][__gcd(elem.F, arr[v])] = elem.S;
        ans += __gcd(elem.F, arr[v]) * elem.S;
    }
    dp[v][arr[v]]++;
    ans += arr[v];
    trav(to, adj[v]) {
        if(to == p)
            continue;
        dfs(to, v);
    }
}
void solve() {
    int n;
    cin >> n;
    arr = vl(n);
    adj = vvi(n);
    dp = vector<map<ll, int>>(n);
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs();
    cout << ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
/*
    Use only when the modular is fixed;
    Computing inverse takes logN time so see whether to store it in a array;
*/
template <int mod = MOD>
struct Modular {
    int value;
    Modular(long long v = 0) {if(v >= MOD || v < -MOD) v %= MOD;value = v; if (value < 0) value += mod;}
    Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}

    Modular& operator+=(Modular const& b) {value += b.value; if (value >= mod) value -= mod; return *this;}
    Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += mod;return *this;}
    Modular& operator*=(Modular const& b) {long long res = (long long)value * b.value;if(res >= MOD){res %= MOD;}value = res;return *this;}

    friend Modular mexp(Modular a, long long e) {
        e %= (mod - 1);
        Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
        return res;
    }
    friend Modular inverse(Modular a) { return mexp(a, mod - 2); }

    Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
    friend Modular operator+(Modular a, Modular const b) { return a += b; }
    friend Modular operator-(Modular a, Modular const b) { return a -= b; }
    friend Modular operator-(Modular const a) { return 0 - a; }
    friend Modular operator*(Modular a, Modular const b) { return a *= b; }
    friend Modular operator/(Modular a, Modular const b) { return a /= b; }
    friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
    friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
    friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};

using Mint = Modular<>;
Mint ans = 0;
vl arr;
vvi adj;
// vector<map<ll, int>> dp;

void dfs(int v, int p, map<ll, ll> gc) {
    map<ll, ll> cp;
    trav(elem, gc) {
        cp[__gcd(elem.F, arr[v])] += elem.S;
        ans += __gcd(elem.F, arr[v]) * elem.S;
    }
    cp[arr[v]]++;
    ans += arr[v];
    trav(to, adj[v]) {
        if(to == p)
            continue;
        dfs(to, v, cp);
    }
}
void solve() {
    int n;
    cin >> n;
    arr = vl(n);
    adj = vvi(n);
    // dp = vector<map<ll, int>>(n);
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(0, -1, map<ll, ll>());
    cout << ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=100050;
const int maxm=200050;
const ll MOD=1e9+7;
struct edge{
	int nxt,to;
};
struct node{
	ll val;
	int tot;
	node(ll val=0,int tot=0):val(val),tot(tot){}
};
bool operator < (node a,node b){
	return a.val<b.val;
}
vector<node> g[maxn];
edge e[maxm];
node tmp[maxn];
ll a[maxn];
int head[maxn];
ll res;
int n,cnt;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
void init(){
	memset(head,-1,sizeof(head));
	res=0;cnt=0;
}
void add(int u,int v){
	e[cnt].to=v;e[cnt].nxt=head[u];head[u]=cnt++;
}
void dfs(int u,int fa){
	for(auto x:g[u]){
		res=(res+x.val*x.tot)%MOD;
	}
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa)	continue;
		int k=0;
		for(auto x:g[u])	tmp[++k]=node(gcd(x.val,a[v]),x.tot);
		tmp[++k]=node(a[v],1);
		sort(tmp+1,tmp+k+1);
		int now=0;
		for(int i=1;i<=k;i++){
			if(tmp[i].val!=tmp[i-1].val)	tmp[++now]=tmp[i];
			else	tmp[now].tot+=tmp[i].tot;
		}
		for(int i=1;i<=now;i++)	g[v].push_back(tmp[i]);
		dfs(v,u);
	}
}
void solve(){
	init();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%lld",&a[i]);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		add(u,v);add(v,u);
	}
	tmp[0]=node(-1,0);
	g[1].push_back(node(a[1],1));
	dfs(1,0);
	printf("%lld\n",res);
}
int main(){
	solve();
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=100050;
const int maxm=200050;
const ll MOD=1e9+7;
struct edge{
	int nxt,to;
};
struct node{
	ll val;
	int tot;
	node(ll val=0,int tot=0):val(val),tot(tot){}
};
bool operator < (node a,node b){
	return a.val<b.val;
}
vector<node> g[maxn];
edge e[maxm];
node tmp[maxn];
ll a[maxn];
int head[maxn];
ll res;
int n,cnt;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
void init(){
	memset(head,-1,sizeof(head));
	res=0;cnt=0;
}
void add(int u,int v){
	e[cnt].to=v;e[cnt].nxt=head[u];head[u]=cnt++;
}
void dfs(int u,int fa){
	for(auto x:g[u]){
		res=(res+x.val*x.tot)%MOD;
	}
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa)	continue;
		int k=0;
		for(auto x:g[u])	tmp[++k]=node(gcd(x.val,a[v]),x.tot);
		tmp[++k]=node(a[v],1);
		sort(tmp+1,tmp+k+1);
		int now=0;
		for(int i=1;i<=k;i++){
			if(tmp[i].val!=tmp[i-1].val)	tmp[++now]=tmp[i];
			else	tmp[now].tot+=tmp[i].tot;
		}
		for(int i=1;i<=now;i++)	g[v].push_back(tmp[i]);
		dfs(v,u);
	}
}
void solve(){
	init();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%lld",&a[i]);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		add(u,v);add(v,u);
	}
	tmp[0]=node(-1,0);
	g[1].push_back(node(a[1],1));
	dfs(1,0);
	printf("%lld\n",res);
}
int main(){
	solve();
	return 0;
}


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

#define int long long
#define fi first
#define se second
#define pb push_back
#define ins insert
#define er erase

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int oo = 1e18 + 7, mod = 1e9 + 7;

const int N = 1e5 + 5;

int n, par[N], d[N], x[N], sparse1[N][17], sparse2[N][17], ans[N];
vector<int> vc[N];

int gcd(int a, int b){
    if(a < b) swap(a, b);
    //cout << a << " " << b << "\n";
    while(b){
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

void dfs(int u, int p){
    for(int i = 0; i < vc[u].size(); i++){
        int v = vc[u][i];
        if(v == p) continue;
        sparse1[v][0] = u;
        sparse2[v][0] = gcd(x[u], x[v]);
        d[v] = d[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i];
	for(int i = 1; i < n; i++){
	    int x, y;
	    cin >> x >> y;
	    vc[x].pb(y);
	    vc[y].pb(x);
	}
	d[1] = 0;
	dfs(1, 0);
	for(int i = 1; i < 17; i++){
	    for(int j = 1; j <= n; j++) sparse1[j][i] = sparse1[sparse1[j][i - 1]][i - 1];
	}
	for(int i = 1; i < 17; i++){
	    for(int j = 1; j <= n; j++) sparse2[j][i] = gcd(sparse2[j][i - 1], sparse2[sparse1[j][i - 1]][i - 1]);
	}
	for(int i = 1; i <= n; i++){
	    //cout << i << "\n";
	    int itr = i, val = x[i], turn = 0;
	    if(!x[i]){
	    	ans[i] = ans[par[i]];
	    	continue;
		}
	    while(itr){
	        ++turn;
	        //cout << itr << "\n";
	        int temp = itr;
	        for(int j = 16; j >= 0; j--) if(d[temp] >= (1 << j) && !(sparse2[temp][j] % val)) temp = sparse1[temp][j];
	        ans[i] += val * (d[itr] - d[temp] + 1);
	        //cout << i << " " << itr << " " << temp << " " << par[temp] << "\n";
	        itr = par[temp];
	        val = gcd(val, x[itr]);
	    }
	    //cout << ans[i] << "\n";
	}
	int sum = 0;
	for(int i = 1; i <= n; i++) sum += ans[i];
	cout << sum;
}


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

#define int long long
#define fi first
#define se second
#define pb push_back
#define ins insert
#define er erase

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int oo = 1e18 + 7, mod = 1e9 + 7;
const int N = 1e5 + 5;

int n, par[N], d[N], x[N], sparse1[N][17], sparse2[N][17], ans[N], arr[N];
vector<int> vc[N];

bool cmp(int a, int b){
    return d[a] < d[b];
}

int gcd(int a, int b){
    if(a < b) swap(a, b);
    //cout << a << " " << b << "\n";
    while(b){
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

void dfs(int u, int p){
    for(int i = 0; i < vc[u].size(); i++){
        int v = vc[u][i];
        if(v == p) continue;
        sparse1[v][0] = u;
        sparse2[v][0] = gcd(x[u], x[v]);
        d[v] = d[u] + 1;
        par[v] = u;
        dfs(v, u);
    }
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i];
	for(int i = 1; i < n; i++){
	    int x, y;
	    cin >> x >> y;
	    vc[x].pb(y);
	    vc[y].pb(x);
	}
	d[1] = 0;
	dfs(1, 0);
	for(int i = 1; i < 17; i++){
	    for(int j = 1; j <= n; j++) sparse1[j][i] = sparse1[sparse1[j][i - 1]][i - 1];
	}
	for(int i = 1; i < 17; i++){
	    for(int j = 1; j <= n; j++) sparse2[j][i] = gcd(sparse2[j][i - 1], sparse2[sparse1[j][i - 1]][i - 1]);
	}
	for(int i = 1; i <= n; i++) arr[i] = i;
	sort(arr + 1, arr + n + 1, cmp);
	for(int i = 1; i <= n; i++){
	    int itr = arr[i], val = x[arr[i]], turn = 0;
	    if(!x[arr[i]]){
	    	ans[arr[i]] = ans[par[arr[i]]];
	    	continue;
		}
	    while(itr){
	        ++turn;
	        //cout << itr << "\n";
	        int temp = itr;
	        for(int j = 16; j >= 0; j--) if(d[temp] >= (1 << j) && !(sparse2[temp][j] % val)) temp = sparse1[temp][j];
	        ans[arr[i]] += val * (d[itr] - d[temp] + 1);
	        ans[arr[i]] %= mod;
	        //cout << i << " " << itr << " " << temp << " " << par[temp] << "\n";
	        itr = par[temp];
	        val = gcd(val, x[itr]);
	    }
	    //cout << ans[i] << "\n";
	}
	int sum = 0;
	for(int i = 1; i <= n; i++) sum += ans[i];
	sum %= mod;
	cout << sum;
}


#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;

const int Inf = 100000;
const int mod = 1000000007;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
vector <int> Adj[100005];
map <long long, int> M[100005];
long long a[100005];
long long ans = 0, ac = 0;

void DFS(int node, int p = 0)
{
	M[node][a[node]]++;
	for(auto x : M[p])
	{
		M[node][__gcd(x.fi, a[node])]++;
	}
	for(auto x : M[node])
	{
		ans += x.fi * x.se % mod;
		ans %= mod;
	}
	for(auto x : Adj[node])
	{
		if(x != p)
			DFS(x, node);
	}
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for(int i = 1; i <= n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		Adj[u].eb(v);
		Adj[v].eb(u);
	}
	DFS(1);
	cout << ans;
}


#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;

const int Inf = 100000;
const int mod = 1000000007;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
vector <int> Adj[100005];
map <long long, int> M[100005];
long long a[100005];
long long ans = 0, ac = 0;

void DFS(int node, int p = 0)
{
	M[node][a[node]]++;
	for(auto x : M[p])
	{
		M[node][__gcd(x.fi, a[node])] += x.se;
	}
	for(auto x : M[node])
	{
		ans += x.fi * x.se % mod;
		ans %= mod;
	}
	for(auto x : Adj[node])
	{
		if(x != p)
		DFS(x, node);
	}
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for(int i = 1; i <= n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		Adj[u].eb(v);
		Adj[v].eb(u);
	}
	DFS(1);
	cout << ans;
}


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

const int maxn = 1e5+5, M = 1e9+7;
const int maxk = 18;
int n;
vector<int> adj[maxn];
ll x[maxn];
int par[maxk][maxn];
ll gc[maxk][maxn];
int depth[maxn];

void root(int i, int p) {
    depth[i] = depth[p] + 1;
    par[0][i] = p;
    gc[0][i] = __gcd(x[i],x[p]);
    for (int k = 1; k < maxk; k++) {
        par[k][i] = par[k-1][par[k-1][i]];
        int jmp = par[k-1][i];
        gc[k][i] = __gcd(gc[k-1][i],gc[k-1][jmp]);
    }
    for (int j: adj[i]) {
        if (j == p) continue;
        root(j,i);
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    root(1,0);
    /*
    for (int i = 1; i <= n; i++) {
        for (int k = 0; k < 4; k++) {
            cout << i << ' ' << k << ": " << gc[k][i] << '\n';
        }
    }
    */
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ll curr = x[i];
        int j = i;
        ll cum = 0;
        //cout << "start " << i << ":\n";
        while (j != 0) {
            int pj = j;
            if (__gcd(gc[0][j],curr) != curr || par[0][j] == 0) {
                j = par[0][j];
                ll add = curr;
                cum = (cum + add) % M;
                curr = __gcd(x[j],curr);
                //printf("j = %d, add = %d, curr = %d\n",j,add,curr);
            }
            else {
                for (int k = maxk-1; k >= 0; k--) {
                    int nj = par[k][j];
                    if (nj == 0) continue;
                    if (__gcd(gc[k][j],curr) == curr) {
                        j = nj;
                    }
                }
                j = par[0][j];
                ll add = ((curr%M) * 1LL*(depth[pj]-depth[j])) % M;
                cum = (cum + add) % M;
                curr = __gcd(x[j],curr);
                //printf("j = %d, add = %d, curr = %d\n",j,add,curr);
            }
        }
        //cout << i << ": " << cum << '\n';
        ans = (ans + cum) % M;
    }
    cout << ans << '\n';
}


// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <list>

// hloya template v25

// ░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░░░░░
// ░░░░░░█░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░█░░░░░
// ░░░░░░█░█░▀░░░░░▀░░▀░░░░█░█░░░░░
// ░░░░░░█░█░░░░░░░░▄▀▀▄░▀░█░█▄▀▀▄░
// █▀▀█▄░█░█░░▀░░░░░█░░░▀▄▄█▄▀░░░█░
// ▀▄▄░▀██░█▄░▀░░░▄▄▀░░░░░░░░░░░░▀▄
// ░░▀█▄▄█░█░░░░▄░░█░░░▄█░░░▄░▄█░░█
// ░░░░░▀█░▀▄▀░░░░░█░██░▄░░▄░░▄░███
// ░░░░░▄█▄░░▀▀▀▀▀▀▀▀▄░░▀▀▀▀▀▀▀░▄▀░
// ░░░░█░░▄█▀█▀▀█▀▀▀▀▀▀█▀▀█▀█▀▀█░░░
// ░░░░▀▀▀▀░░▀▀▀░░░░░░░░▀▀▀░░▀▀░░░░

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

bool dbg = 0;

clock_t start_time = clock();
#define current_time fixed<<setprecision(6)<<(ld)(clock()-start_time)/CLOCKS_PER_SEC

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

#define ll long long
#define ld long double
#define pii pair<int,int>
#define umap unordered_map<int, int>

#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)

// #define endl '\n'
#define ln(i,n) " \n"[(i) == (n) - 1]

void bad(string mes = "Impossible"){cout << mes;exit(0);}
void bad(int mes){cout << mes;exit(0);}

template<typename T>
string bin(T x, int st = 2){
    string ans = "";
    while (x > 0){
        ans += char('0' + x % st);
        x /= st;
    }
    reverse(ans.begin(), ans.end());
    return ans.empty() ? "0" : ans;
}

template<typename T>
void upmax(T& x, T y) {
    x = max(x, y);
}

template<typename T>
void upmin(T& x, T y) {
    x = min(x, y);
}

// inline int popcount(int x){
//     int count = 0;
//     __asm__ volatile("POPCNT %1, %0;":"=r"(count):"r"(x):);
//     return count;
// }

template<typename T>
T input(){
    T ans = 0, m = 1;
    char c = ' ';

    while (!((c >= '0' && c <= '9') || c == '-')) {
        c = getchar();
    }

    if (c == '-')
        m = -1, c = getchar();
    while (c >= '0' && c <= '9'){
        ans = ans * 10 + (c - '0'), c = getchar();
    }
    return ans * m;
}

template<typename T> void read(T& a) { a = input<T>(); }
template<typename T> void read(T& a, T& b) { read(a), read(b); }
template<typename T> void read(T& a, T& b, T& c) { read(a, b), read(c); }
template<typename T> void read(T& a, T& b, T& c, T& d) { read(a, b), read(c, d); }

const int inf = 1e9 + 20;
const short short_inf = 3e4 + 20;
const long double eps = 1e-6;
const int maxn = (int)1e5 + 12;//, base = 1e9 + 7;
const ll llinf = 2e18 + 5;
const double PI = acos(-1.0);

const int mod = 1e9 + 7;

template<typename T>
T binpow(T n, T s)
{
    if (s <= 0)
        return 1LL;
    if (s % 2 == 0){
        T b = binpow(n, s / 2);
        return ( 1LL * b * b ) % mod;
    } else {
        return (1LL* binpow(n, s - 1) * n) % mod;
    }
}

ll x[maxn];
vector<pair<ll, int>> rng[maxn];
vector<pair<ll, int>> tmp;
vector<int> g[maxn];
ll ans = 0;

ll gc(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a + b;
}

void dfs(int v, int p = -1) {
    if (v == 0) {
        rng[v].pb({x[v], 1});
    } else {
        rng[v] = rng[p];
        rng[v].pb({x[v], 1});
        for (int i = 0; i < rng[v].size(); i++) {
            rng[v][i].f = gc(rng[v][i].f, x[v]);
        }
        tmp.clear();
        for (int i = 0; i < rng[v].size(); i++) {
            if (tmp.empty() || tmp.back().f != rng[v][i].f) {
                tmp.pb(rng[v][i]);
            } else {
                tmp.back().s += rng[v][i].s;
            }
        }
        rng[v] = tmp;
    }
    for (int i = 0; i < rng[v].size(); i++) {
        ans += rng[v][i].f * rng[v][i].s % mod;
        if (ans >= mod)
            ans -= mod;
    }
    for (auto to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
    }
}

int main() {
    // files1;
    fast_io;

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    for (int i = 0; i + 1 < n; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }

    dfs(0);
    cout << ans;
    return 0;
}


// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <list>

// hloya template v25

// ░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░░░░░
// ░░░░░░█░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░█░░░░░
// ░░░░░░█░█░▀░░░░░▀░░▀░░░░█░█░░░░░
// ░░░░░░█░█░░░░░░░░▄▀▀▄░▀░█░█▄▀▀▄░
// █▀▀█▄░█░█░░▀░░░░░█░░░▀▄▄█▄▀░░░█░
// ▀▄▄░▀██░█▄░▀░░░▄▄▀░░░░░░░░░░░░▀▄
// ░░▀█▄▄█░█░░░░▄░░█░░░▄█░░░▄░▄█░░█
// ░░░░░▀█░▀▄▀░░░░░█░██░▄░░▄░░▄░███
// ░░░░░▄█▄░░▀▀▀▀▀▀▀▀▄░░▀▀▀▀▀▀▀░▄▀░
// ░░░░█░░▄█▀█▀▀█▀▀▀▀▀▀█▀▀█▀█▀▀█░░░
// ░░░░▀▀▀▀░░▀▀▀░░░░░░░░▀▀▀░░▀▀░░░░

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

bool dbg = 0;

clock_t start_time = clock();
#define current_time fixed<<setprecision(6)<<(ld)(clock()-start_time)/CLOCKS_PER_SEC

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

#define ll long long
#define ld long double
#define pii pair<int,int>
#define umap unordered_map<int, int>

#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)

// #define endl '\n'
#define ln(i,n) " \n"[(i) == (n) - 1]

void bad(string mes = "Impossible"){cout << mes;exit(0);}
void bad(int mes){cout << mes;exit(0);}

template<typename T>
string bin(T x, int st = 2){
    string ans = "";
    while (x > 0){
        ans += char('0' + x % st);
        x /= st;
    }
    reverse(ans.begin(), ans.end());
    return ans.empty() ? "0" : ans;
}

template<typename T>
void upmax(T& x, T y) {
    x = max(x, y);
}

template<typename T>
void upmin(T& x, T y) {
    x = min(x, y);
}

// inline int popcount(int x){
//     int count = 0;
//     __asm__ volatile("POPCNT %1, %0;":"=r"(count):"r"(x):);
//     return count;
// }

template<typename T>
T input(){
    T ans = 0, m = 1;
    char c = ' ';

    while (!((c >= '0' && c <= '9') || c == '-')) {
        c = getchar();
    }

    if (c == '-')
        m = -1, c = getchar();
    while (c >= '0' && c <= '9'){
        ans = ans * 10 + (c - '0'), c = getchar();
    }
    return ans * m;
}

template<typename T> void read(T& a) { a = input<T>(); }
template<typename T> void read(T& a, T& b) { read(a), read(b); }
template<typename T> void read(T& a, T& b, T& c) { read(a, b), read(c); }
template<typename T> void read(T& a, T& b, T& c, T& d) { read(a, b), read(c, d); }

const int inf = 1e9 + 20;
const short short_inf = 3e4 + 20;
const long double eps = 1e-6;
const int maxn = (int)1e5 + 12;//, base = 1e9 + 7;
const ll llinf = 2e18 + 5;
const double PI = acos(-1.0);

const int mod = 1e9 + 7;

template<typename T>
T binpow(T n, T s)
{
    if (s <= 0)
        return 1LL;
    if (s % 2 == 0){
        T b = binpow(n, s / 2);
        return ( 1LL * b * b ) % mod;
    } else {
        return (1LL* binpow(n, s - 1) * n) % mod;
    }
}

ll x[maxn];
vector<pair<ll, int>> rng[maxn];
vector<pair<ll, int>> tmp;
vector<int> g[maxn];
ll ans = 0;

ll gc(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a + b;
}

void dfs(int v, int p = -1) {
    if (v == 0) {
        rng[v].pb({x[v], 1});
    } else {
        rng[v] = rng[p];
        rng[v].pb({x[v], 1});
        for (int i = 0; i < rng[v].size(); i++) {
            rng[v][i].f = gc(rng[v][i].f, x[v]);
        }
        tmp.clear();
        for (int i = 0; i < rng[v].size(); i++) {
            if (tmp.empty() || tmp.back().f != rng[v][i].f) {
                tmp.pb(rng[v][i]);
            } else {
                tmp.back().s += rng[v][i].s;
            }
        }
        rng[v] = tmp;
    }
    for (int i = 0; i < rng[v].size(); i++) {
        ans += rng[v][i].f * rng[v][i].s;
    }
    for (auto to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
    }
}

int main() {
    // files1;
    fast_io;

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    for (int i = 0; i + 1 < n; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }

    dfs(0);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll inf = 1e18;
const int mod = 1e9+7; //998244353;
const int maxn = 2e5+5;
const int Xg[4] = {1,0,-1,0}, Yg[4] = {0,1,0,-1};
ll modpw(ll a,ll e) {if(e==0)return 1;ll x=modpw(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int n,p[maxn],x,y;
ll a[maxn],g,ans;
vi E[maxn];

void dfs(int nd,int pr){
	p[nd]=pr;
	for(auto i : E[nd]) if(i != pr) dfs(i,nd);
}

void f(int nd){
	if(!nd) return;
	g = gcd(g,a[nd]);
	ans = (ans + g%mod)%mod;
	f(p[nd]);
}

int main(){
	#ifdef LOCAL
		clock_t TSTART = clock();
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin>>n;
	for(int i = 1;i <= n;i++) cin>>a[i];
	for(int i = 1;i < n;i++) cin>>x>>y,E[x].pb(y),E[y].pb(x);
	dfs(1,0);
	for(int i = 1;i <= n;i++){
		g=0;
		f(i);
	}
	cout<<ans;
	#ifdef LOCAL
		cout << "\nTime elapsed: " << double(clock()-TSTART) / CLOCKS_PER_SEC << " s.\n";
	#endif
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll inf = 1e18;
const int mod = 1e9+7; //998244353;
const int maxn = 2e5+5;
const int Xg[4] = {1,0,-1,0}, Yg[4] = {0,1,0,-1};
ll modpw(ll a,ll e) {if(e==0)return 1;ll x=modpw(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int n,x,y;
ll a[maxn],ans;
vi E[maxn];
vector<pll> v[maxn];
unordered_map<ll,int> m;

void dfs(int nd,int pr){
	m.clear();
	m[a[nd]]=1;
	for(auto i : v[pr]) m[gcd(i.ff,a[nd])]+=i.ss;
	for(auto i : m) v[nd].pb({i.ff,i.ss}),ans = (ans + ((i.ff%mod)*i.ss)%mod)%mod;
	for(auto i : E[nd])
		if(i != pr) dfs(i,nd);
}

int main(){
	#ifdef LOCAL
		clock_t TSTART = clock();
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n;
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i < n;i++) cin>>x>>y,E[x].pb(y),E[y].pb(x);

	dfs(1,0);
	cout<<ans;
	#ifdef LOCAL
		cout << "\nTime elapsed: " << double(clock()-TSTART) / CLOCKS_PER_SEC << " s.\n";
	#endif
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll inf = 1e18;
const int mod = 1e9+7; //998244353;
const int maxn = 2e5+5;
const int Xg[4] = {1,0,-1,0}, Yg[4] = {0,1,0,-1};
ll modpw(ll a,ll e) {if(e==0)return 1;ll x=modpw(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int n,p[maxn],x,y;
ll a[maxn],g,ans;
vi E[maxn];

void dfs(int nd,int pr){
	p[nd]=pr;
	for(auto i : E[nd]) if(i != pr) dfs(i,nd);
}

void f(int nd){
	if(!nd) return;
	g = gcd(g,a[nd]);
	ans = (ans + g%mod)%mod;
	f(p[nd]);
}

int main(){
	#ifdef LOCAL
		clock_t TSTART = clock();
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin>>n;
	for(int i = 1;i <= n;i++) cin>>a[i];
	for(int i = 1;i < n;i++) cin>>x>>y,E[x].pb(y),E[y].pb(x);
	dfs(1,0);
	for(int i = 1;i <= n;i++){
		g=0;
		f(i);
	}
	cout<<ans;
	#ifdef LOCAL
		cout << "\nTime elapsed: " << double(clock()-TSTART) / CLOCKS_PER_SEC << " s.\n";
	#endif
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll inf = 1e18;
const int mod = 1e9+7; //998244353;
const int maxn = 2e5+5;
const int Xg[4] = {1,0,-1,0}, Yg[4] = {0,1,0,-1};
ll modpw(ll a,ll e) {if(e==0)return 1;ll x=modpw(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int n,x,y;
ll a[maxn],ans;
vi E[maxn];
vector<pii> v[maxn];
map<ll,int> m;

void dfs(int nd,int pr){
	m.clear();
	m[a[nd]]=1;
	for(auto i : v[pr]) m[gcd(i.ff,a[nd])]+=i.ss;
	for(auto i : m) v[nd].pb({i.ff,i.ss}),ans = (ans + ((i.ff%mod)*i.ss)%mod)%mod;
	for(auto i : E[nd])
		if(i != pr) dfs(i,nd);
}

int main(){
	#ifdef LOCAL
		clock_t TSTART = clock();
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n;
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i < n;i++) cin>>x>>y,E[x].pb(y),E[y].pb(x);

	dfs(1,0);
	cout<<ans;
	#ifdef LOCAL
		cout << "\nTime elapsed: " << double(clock()-TSTART) / CLOCKS_PER_SEC << " s.\n";
	#endif
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll inf = 1e18;
const int mod = 1e9+7; //998244353;
const int maxn = 2e5+5;
const int Xg[4] = {1,0,-1,0}, Yg[4] = {0,1,0,-1};
ll modpw(ll a,ll e) {if(e==0)return 1;ll x=modpw(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int n,x,y;
ll a[maxn],ans;
vi E[maxn];
vector<pll> v[maxn];
map<ll,int> m;

void dfs(int nd,int pr){
	m.clear();
	m[a[nd]]=1;
	for(auto i : v[pr]) m[gcd(i.ff,a[nd])]+=i.ss;
	for(auto i : m) v[nd].pb({i.ff,i.ss}),ans = (ans + ((i.ff%mod)*i.ss)%mod)%mod;
	for(auto i : E[nd])
		if(i != pr) dfs(i,nd);
}

int main(){
	#ifdef LOCAL
		clock_t TSTART = clock();
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n;
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i < n;i++) cin>>x>>y,E[x].pb(y),E[y].pb(x);

	dfs(1,0);
	cout<<ans;
	#ifdef LOCAL
		cout << "\nTime elapsed: " << double(clock()-TSTART) / CLOCKS_PER_SEC << " s.\n";
	#endif
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll inf = 1e18;
const int mod = 1e9+7; //998244353;
const int maxn = 2e5+5;
const int Xg[4] = {1,0,-1,0}, Yg[4] = {0,1,0,-1};
ll modpw(ll a,ll e) {if(e==0)return 1;ll x=modpw(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int n,x,y;
ll a[maxn],ans;
vi E[maxn];
vector<pll> v[maxn];
map<ll,int> m;

void dfs(int nd,int pr){
	m.clear();
	m[a[nd]]=1;
	for(auto i : v[pr]) m[gcd(i.ff,a[nd])]+=i.ss;
	for(auto i : m) v[nd].pb({i.ff,i.ss}),ans = (ans + ((i.ff%mod)*i.ss)%mod)%mod;
	for(auto i : E[nd])
		if(i != pr) dfs(i,nd);
}

int main(){
	#ifdef LOCAL
		clock_t TSTART = clock();
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n;
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i < n;i++) cin>>x>>y,E[x].pb(y),E[y].pb(x);

	dfs(1,0);
	cout<<ans;
	#ifdef LOCAL
		cout << "\nTime elapsed: " << double(clock()-TSTART) / CLOCKS_PER_SEC << " s.\n";
	#endif
}