#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
long long c[N], g[N][32], h[N];
long long ans;
int p[N][32];
int n;
vector<int> t[N];
long long _gcd(long long a, long long b) {
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
void bin_lift(long long goal, int v) {
  if (v == 0) return;
  int u = v;
  for (int i = 20; i >= 0; i--) {
    if (p[v][i] != 0 && _gcd(goal, g[v][i]) == goal) {
      v = p[v][i];
    }
  }
  if (p[v][0] != 0 && _gcd(goal, g[v][0]) == goal) {
    v = p[v][0];
  }
  ans += (h[u] - h[v] + 1) * goal;
  ans %= mod;
  bin_lift(_gcd(goal, g[v][0]), p[v][0]);
}
void dfs(int v = 1) {
  h[v] = h[p[v][0]] + 1;
  for (int j = 1; j <= 20; j++) {
    p[v][j] = p[p[v][j - 1]][j - 1];
    g[v][j] = _gcd(g[v][j - 1], g[p[v][j - 1]][j - 1]);
  }
  bin_lift(g[v][0], p[v][0]);
  for (int to : t[v]) {
    if (to != p[v][0]) {
      g[to][0] = _gcd(c[v], c[to]);
      p[to][0] = v;
      dfs(to);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &c[i]);
    ans += c[i];
    ans %= mod;
  }
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    t[a].push_back(b);
    t[b].push_back(a);
  }
  dfs();
  printf("%lld", ans % mod);
}
