#include <bits/stdc++.h>
using namespace std;
const long long N = 100010, Mod = 1e9 + 7;
inline long long read() {
  long long s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
long long n, a[N], res;
long long head[N], maxE;
struct Edge {
  long long nxt, to;
} e[N << 1];
inline void Add(long long u, long long v) {
  e[++maxE].nxt = head[u];
  head[u] = maxE;
  e[maxE].to = v;
}
vector<pair<long long, long long> > G[N];
inline long long gcd(long long x, long long y) {
  if (x < y) swap(x, y);
  return y ? gcd(y, x % y) : x;
}
void DFS(long long x, long long fa) {
  vector<pair<long long, long long> > F;
  for (register long long i = 0; i < (long long)G[fa].size(); i++) {
    F.emplace_back(make_pair(gcd(G[fa][i].first, a[x]), G[fa][i].second));
  }
  F.emplace_back(make_pair(a[x], 1));
  sort(F.begin(), F.end());
  long long now = 0;
  for (register long long i = 0; i < (long long)F.size(); i++) {
    if ((!i) || F[i].first == F[i - 1].first)
      now += F[i].second;
    else
      G[x].emplace_back(make_pair(F[i - 1].first, now)),
          res = (res + F[i - 1].first % Mod * now % Mod) % Mod,
          now = F[i].second;
  }
  G[x].emplace_back(make_pair(F[(long long)F.size() - 1].first, now));
  res = (res + F[(long long)F.size() - 1].first % Mod * now % Mod) % Mod;
  for (long long i = head[x]; i; i = e[i].nxt) {
    long long v = e[i].to;
    if (v == fa) continue;
    DFS(v, x);
  }
}
signed main() {
  n = read();
  for (register long long i = 1; i <= n; i++) a[i] = read();
  for (register long long i = 1; i < n; i++) {
    long long u, v;
    u = read(), v = read();
    Add(u, v), Add(v, u);
  }
  DFS(1, 0);
  printf("%lld\n", res);
  return 0;
}
