#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18 + 7, mod = 1e9 + 7;
const long long N = 1e5 + 5;
long long n, par[N], d[N], x[N], sparse1[N][17], sparse2[N][17], ans[N], arr[N];
vector<long long> vc[N];
bool cmp(long long a, long long b) { return d[a] < d[b]; }
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (b) {
    long long temp = b;
    b = a % b;
    a = temp;
  }
  return a;
}
void dfs(long long u, long long p) {
  for (long long i = 0; i < vc[u].size(); i++) {
    long long v = vc[u][i];
    if (v == p) continue;
    sparse1[v][0] = u;
    sparse2[v][0] = gcd(x[u], x[v]);
    d[v] = d[u] + 1;
    par[v] = u;
    dfs(v, u);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> x[i];
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    vc[x].push_back(y);
    vc[y].push_back(x);
  }
  d[1] = 0;
  dfs(1, 0);
  for (long long i = 1; i < 17; i++) {
    for (long long j = 1; j <= n; j++)
      sparse1[j][i] = sparse1[sparse1[j][i - 1]][i - 1];
  }
  for (long long i = 1; i < 17; i++) {
    for (long long j = 1; j <= n; j++)
      sparse2[j][i] = gcd(sparse2[j][i - 1], sparse2[sparse1[j][i - 1]][i - 1]);
  }
  for (long long i = 1; i <= n; i++) arr[i] = i;
  sort(arr + 1, arr + n + 1, cmp);
  for (long long i = 1; i <= n; i++) {
    long long itr = arr[i], val = x[arr[i]], turn = 0;
    if (!x[arr[i]]) {
      ans[arr[i]] = ans[par[arr[i]]];
      continue;
    }
    while (itr) {
      ++turn;
      long long temp = itr;
      for (long long j = 16; j >= 0; j--)
        if (d[temp] >= (1 << j) && !(sparse2[temp][j] % val))
          temp = sparse1[temp][j];
      ans[arr[i]] += val * (d[itr] - d[temp] + 1);
      ans[arr[i]] %= mod;
      itr = par[temp];
      val = gcd(val, x[itr]);
    }
  }
  long long sum = 0;
  for (long long i = 1; i <= n; i++) sum += ans[i];
  sum %= mod;
  cout << sum;
}
