#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100005;
const long long MOD = 1e9 + 7;
long long x[MAXN];
vector<long long> g[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, map<long long, long long> mp) {
  map<long long, long long> new_mp;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    long long ind = it->first;
    long long g = gcd(ind, x[v]);
    ans += g * mp[ind];
    ans %= MOD;
    new_mp[g] += mp[ind];
  }
  new_mp[x[v]]++;
  ans += x[v];
  ans %= MOD;
  for (long long i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (to != p) {
      dfs(to, v, new_mp);
    }
  }
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base ::sync_with_stdio(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  map<long long, long long> tmp;
  dfs(0, -1, tmp);
  cout << ans;
  return 0;
}
