#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int bea[100005];
vector<int> g[100005];
map<long long int, long long int> m[100005];
long long int ans = 0;
long long int mod1(string num, long long int a1) {
  long long int res = 0;
  for (int i = 0; i < num.length(); i++)
    res = (res * 10 + (int)num[i] - '0') % a1;
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int x, int p) {
  for (auto u : m[p]) {
    long long int pos = gcd(bea[x], u.first);
    long long int pos1 = pos * u.second;
    ans = (ans + pos1 % mod) % mod;
    m[x][pos] += u.second;
  }
  m[x][bea[x]]++;
  ans = (ans + bea[x] % mod) % mod;
  for (auto u : g[x]) {
    if (u != p) {
      dfs(u, x);
    }
  }
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> bea[i];
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 1);
  cout << ans << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
