#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long GCD(long long u, long long v) {
  while (v != 0) {
    long long r = u % v;
    u = v;
    v = r;
  }
  return u;
}
int n;
vector<long long> x;
vector<vector<int>> e;
vector<vector<pair<long long, int>>> gcdseq;
long long ans = 0;
void dfs(int node, int p, int dep) {
  long long num = x[node];
  ans += num;
  for (auto gcp : gcdseq[p]) {
    long long ngcd = GCD(num, gcp.first);
    if (gcdseq[node].empty() || gcdseq[node].back().first != ngcd)
      gcdseq[node].push_back({ngcd, gcp.second});
  }
  if (gcdseq[node].empty() || gcdseq[node].back().first != num)
    gcdseq[node].push_back({num, dep});
  for (int i = 0; i + 1 < (int)gcdseq[node].size(); ++i) {
    ans += gcdseq[node][i].first *
           (gcdseq[node][i + 1].second - gcdseq[node][i].second);
    ans %= MOD;
  }
  ans += gcdseq[node].back().first * (dep - gcdseq[node].back().second);
  ans %= MOD;
  for (int ch : e[node]) {
    if (ch == p) continue;
    dfs(ch, node, dep + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  x.resize(n + 1);
  e.resize(n + 1);
  gcdseq.resize(n + 1);
  for (int i = 1; i <= n; ++i) cin >> x[i];
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1, 0, 0);
  cout << ans << endl;
  return 0;
}
