#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
int h[N], e[N << 1], ne[N << 1], idx;
int n;
long long w[N];
long long res;
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
void dfs(int u, int fa, const map<long long, int> &mp) {
  map<long long, int> temp;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    auto x = gcd(it->first, w[u]);
    temp[x] += it->second;
  }
  temp[w[u]]++;
  for (auto it = temp.begin(); it != temp.end(); it++)
    res = (res + it->first % mod * it->second % mod) % mod;
  for (int i = h[u]; ~i; i = ne[i]) {
    int p = e[i];
    if (p == fa) continue;
    dfs(p, u, temp);
  }
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  memset(h, -1, sizeof h);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  map<long long, int> mp;
  dfs(1, -1, mp);
  cout << res << endl;
  return 0;
}
