#include <bits/stdc++.h>
using namespace std;
long long n, i, u, v, x[100005], j, dep[100005], gc[17][100005], f[17][100005],
    ans = 0, dp[100005], fr[100005];
const long long mod = 1e9 + 7;
vector<long long> s[100005];
long long gcd(long long x, long long y) {
  return y == 0 ? x : (x == 0 ? y : gcd(y, x % y));
}
long long M(long long x) { return x >= mod ? x - mod : x; }
long long opt(long long p) {
  long long i, gk, tp, u, ans = 0;
  if (x[p] == 0) return dp[fr[p]];
  tp = p;
  gk = x[p];
  while (tp) {
    u = tp;
    for (i = 16; i >= 0; i--)
      if (gc[i][u] % gk == 0) u = f[i][u];
    ans = (ans + (dep[tp] - max(1LL, dep[u]) + 1) * gk) % mod;
    tp = f[0][u];
    gk = gcd(gk, x[tp]);
  }
  dp[p] = ans;
  return ans;
}
void dfs(int p, int ff) {
  int i, v;
  f[0][p] = ff;
  if (x[p] != 0)
    fr[p] = p;
  else
    fr[p] = fr[ff];
  dep[p] = dep[ff] + 1;
  gc[0][p] = gcd(x[p], x[ff]);
  for (i = 0; i < s[p].size(); i++) {
    v = s[p][i];
    if (v == ff) continue;
    dfs(v, p);
  }
}
void dfs1(int p, int ff) {
  int i, v;
  ans = M(ans + opt(p));
  for (i = 0; i < s[p].size(); i++) {
    v = s[p][i];
    if (v == ff) continue;
    dfs1(v, p);
  }
}
int main() {
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) scanf("%lld", &x[i]);
  for (i = 1; i < n; i++) {
    scanf("%lld%lld", &u, &v);
    s[u].push_back(v);
    s[v].push_back(u);
  }
  dfs(1, 0);
  for (i = 1; i < 17; i++) {
    for (j = 1; j <= n; j++) {
      f[i][j] = f[i - 1][f[i - 1][j]];
      gc[i][j] = gcd(gc[i - 1][j], gc[i - 1][f[i - 1][j]]);
    }
  }
  dfs1(1, 0);
  printf("%lld\n", ans);
  return 0;
}
