#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
long long mod = 1e9 + 7;
map<long long, int> m[MAXN];
int n;
long long a[MAXN], ans;
vector<int> G[MAXN];
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
void dfs(int x, int fa) {
  map<long long, int>::iterator it;
  it = m[fa].begin();
  while (it != m[fa].end()) {
    long long d = gcd(a[x], it->first);
    m[x][d] += it->second;
    it++;
  }
  m[x][a[x]]++;
  it = m[x].begin();
  while (it != m[x].end()) {
    ans = (ans + (it->first) * (it->second) % mod) % mod;
    it++;
  }
  for (int i = 0; i < G[x].size(); ++i) {
    if (G[x][i] == fa) continue;
    dfs(G[x][i], x);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(1, 0);
  printf("%lld", ans);
  return 0;
}
