#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 5;
vector<pair<long long, long long> > c[maxn], s;
vector<int> G[maxn];
bool vis[maxn];
long long b[maxn], ans;
int N;
long long gcd(long long x, long long y) {
  if (x == 0 || y == 0) return max(x, y);
  return gcd(y, x % y);
}
void dfs(int x, int f) {
  vis[x] = 1;
  s.clear();
  if (f) {
    for (auto t : c[f]) {
      s.push_back(pair<long long, long long>(gcd(t.first, b[x]), t.second));
    }
  }
  s.push_back(pair<long long, long long>(b[x], 1));
  sort(s.begin(), s.end());
  c[x].push_back(s[0]);
  int n = 1;
  for (int i = 1; i <= int(s.size() - 1); i++) {
    if (s[i].first == s[i - 1].first) {
      c[x][n - 1].second += s[i].second;
    } else {
      c[x].push_back(s[i]);
      n++;
    }
  }
  for (auto t : c[x]) {
    ans = (ans + t.first * t.second % mod) % mod;
  }
  for (auto t : G[x])
    if (!vis[t]) dfs(t, x);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%lld", &b[i]);
  for (int i = 1; i <= N - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1, 0);
  printf("%d\n", ans);
}
