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