#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 100010;
struct edge {
  int v, next;
} e[maxn << 1];
int n, p[maxn], len;
long long x[maxn], ans;
void init() {
  memset(p, -1, sizeof p);
  len = 0;
}
void insert(int u, int v) {
  e[len].v = v;
  e[len].next = p[u];
  p[u] = len++;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int u, int fa, map<long long, long long> p1) {
  map<long long, long long> p2;
  for (map<long long, long long>::iterator it = p1.begin(); it != p1.end();
       it++) {
    pair<long long, long long> now = (*it);
    long long d = gcd(now.first, x[u]);
    ans = (ans + d * now.second % mod) % mod;
    p2[d] += now.second;
  }
  p2[x[u]]++;
  ans = (ans + x[u]) % mod;
  p1.clear();
  for (int i = p[u]; i != -1; i = e[i].next) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, u, p2);
  }
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x[i]);
  }
  int u, v;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    insert(u, v);
    insert(v, u);
  }
  map<long long, long long> mp;
  dfs(1, -1, mp);
  printf("%lld\n", ans);
  return 0;
}
