#include <bits/stdc++.h>
using namespace std;
const int N = 200004, M = 19;
vector<int> g[N];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int d[N], fa[N][M], n;
long long w[N][M], a[N], mod = 1000000007;
void bfs() {
  d[1] = 1;
  for (int i = 0; i < M; i++) w[1][i] = a[1];
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : g[u]) {
      if (d[v]) continue;
      d[v] = d[u] + 1;
      fa[v][0] = u;
      w[v][0] = a[v];
      for (int i = 1; i < M; i++) {
        fa[v][i] = fa[fa[v][i - 1]][i - 1];
        w[v][i] = gcd(w[v][i - 1], w[fa[v][i - 1]][i - 1]);
      }
      q.push(v);
    }
  }
}
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  bfs();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long nw = a[i];
    int pre = d[i];
    for (;;) {
      int v = i;
      for (int j = M - 1; j >= 0; j--)
        if (w[v][j] == 0) v = fa[v][j];
      for (int j = M - 1; j >= 0; j--)
        if (gcd(nw, w[v][j]) == nw) v = fa[v][j];
      ans = (ans + nw * (pre - d[v])) % mod;
      if (v == 0) break;
      nw = gcd(nw, a[v]);
      pre = d[v];
    }
  }
  printf("%lld\n", ans);
}
