#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000001, mo = 1e9 + 7;
set<long long> s;
map<long long, long long> mp;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}
long long n, kl, head[maxn], ans, sta, sta2, maxdis, x, y, z, a[maxn];
struct line {
  long long f, to, next, val;
} q[maxn * 2];
void pushline(long long f, long long t) {
  q[++kl].next = head[f];
  head[f] = kl;
  q[kl].to = t;
}
void dfs1(long long x, long long fa) {
  set<long long> tmp = s;
  map<long long, long long> tmpm = mp;
  mp.clear();
  s.clear();
  for (set<long long>::iterator i = tmp.begin(); i != tmp.end(); i++) {
    long long v = gcd(*i, a[x]);
    s.insert(v), ans += v * tmpm[*i];
    mp[v] += tmpm[*i];
    ans %= mo;
  }
  ans += a[x], s.insert(a[x]), mp[a[x]]++, ans %= mo;
  for (long long p = head[x]; p; p = q[p].next) {
    long long v = q[p].to;
    if (v == fa) continue;
    dfs1(v, x);
  }
  s = tmp;
  mp = tmpm;
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    pushline(x, y);
    pushline(y, x);
  }
  dfs1(1, 0);
  cout << ans % mo;
  return 0;
}
