#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int aaa = 1;
using namespace std;
const long long mod = 1e9 + 7;
long long value[100005];
set<int> sett[100005];
map<long long, int> vec[100005];
long long ans = 0;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void dfs(int u, int father) {
  set<int>::iterator it;
  for (it = sett[u].begin(); it != sett[u].end(); it++) {
    int v = *it;
    if (v == father) continue;
    map<long long, int>::iterator itm;
    for (itm = vec[u].begin(); itm != vec[u].end(); itm++) {
      long long temp = gcd(itm->first, value[v]);
      ans = (ans + temp * itm->second % mod) % mod;
      vec[v][temp] += itm->second;
    }
    vec[v][value[v]]++;
    dfs(v, u);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &value[i]);
    ans += value[i];
    ans %= mod;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    sett[u].insert(v);
    sett[v].insert(u);
  }
  vec[1][value[1]]++;
  dfs(1, 0);
  printf("%lld", ans);
}
