#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, H = 18, mod = 1e9 + 7;
int n, dep[N], fa[N][H];
long long ans, a[N], wg[N][H];
vector<int> g[N];
void add(int x, int y) { g[x].push_back(y); }
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
void dfs(int x, int p) {
  dep[x] = dep[p] + 1, fa[x][0] = p, wg[x][0] = a[p];
  for (int i = 1; i < H; ++i) {
    fa[x][i] = fa[fa[x][i - 1]][i - 1];
    wg[x][i] = gcd(wg[x][i - 1], wg[fa[x][i - 1]][i - 1]);
  }
  for (auto y : g[x]) {
    if (y != p) {
      dfs(y, x);
    }
  }
}
long long calc(int x, long long g) {
  if (!x) {
    return 0;
  }
  int y = x;
  for (int i = H - 1; ~i; --i) {
    if (fa[y][i]) {
      if (!g) {
        if (wg[y][i] == 0) {
          y = fa[y][i];
        }
      } else {
        if (wg[y][i] % g == 0) {
          y = fa[y][i];
        }
      }
    }
  }
  long long ret = g * (dep[x] - dep[y] + 1) % mod;
  ret = (ret + calc(fa[y][0], gcd(g, wg[y][0]))) % mod;
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  dfs(1, 0);
  ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = (ans + calc(i, a[i])) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
