#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100005;
const long long MOD = 1e9 + 7;
long long n;
long long x[MAXN];
vector<long long> g[MAXN];
map<long long, long long> mp[MAXN];
long long ans = 0;
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
void dfs(long long v, long long p) {
  mp[v][x[v]] = 1;
  ans += x[v];
  ans %= MOD;
  if (p != -1) {
    for (pair<long long, long long> pa : mp[p]) {
      long long g = gcd(pa.first, x[v]);
      mp[v][g] += pa.second;
      ans += g * pa.second;
      ans %= MOD;
    }
  }
  for (long long to : g[v]) {
    if (to != p) {
      dfs(to, v);
    }
  }
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, -1);
  cout << ans;
  return 0;
}
