#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, inv2 = (MOD + 1) / 2;
double eps = 1e-4;
int INF = 1 << 30;
long long inf = 5e13;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int head[200010], vet[200010], nxt[200010], fa[200010], d[200010], vis[200010],
    tot;
long long a[200010], ans;
pair<long long, long long> b[200010];
vector<pair<long long, long long> > c[200010];
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
void add(int a, int b) {
  nxt[++tot] = head[a];
  vet[tot] = b;
  head[a] = tot;
}
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
void dfs(int u, int fa) {
  if (fa) {
    for (int i = 0; i < c[fa].size(); i++) c[u].push_back(c[fa][i]);
  }
  for (int i = 0; i < c[u].size(); i++)
    c[u][i].first = gcd(c[u][i].first, a[u]);
  int m = 0;
  for (int i = 0; i < c[u].size(); i++) b[++m] = c[u][i];
  sort(b + 1, b + m + 1);
  c[u].clear();
  for (int i = (int)1; i <= (int)m; i++) {
    int now = (int)c[u].size() - 1;
    if (now == -1 || b[i].first != c[u][now].first)
      c[u].push_back(b[i]);
    else
      c[u][now].second = (c[u][now].second + b[i].second) % MOD;
  }
  c[u].push_back(make_pair(a[u], 1));
  for (int i = 0; i < c[u].size(); i++)
    ans = (ans + c[u][i].first % MOD * c[u][i].second % MOD) % MOD;
  int e = head[u];
  while (e) {
    int v = vet[e];
    if (v != fa) dfs(v, u);
    e = nxt[e];
  }
}
int main() {
  int n = read();
  for (int i = (int)1; i <= (int)n; i++) scanf("%I64d", &a[i]);
  tot = 0;
  for (int i = (int)1; i <= (int)n; i++) head[i] = 0;
  for (int i = (int)1; i <= (int)n - 1; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  printf("%I64d\n", ans);
  return 0;
}
