#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
double pi = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long powerm(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % M;
    y = y >> 1;
    x = (x * x) % M;
  }
  return res % M;
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b > a) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int N = 1e5 + 5;
vector<int> adj[N];
vector<long long> a(N);
long long ans;
void dfs(map<long long, long long> m, int u, int par = -1) {
  map<long long, long long> m1;
  m1[a[u]] = 1;
  ans = (ans + a[u]) % M;
  for (auto it : m) {
    long long g = gcd(it.first, a[u]);
    ans = (ans + ((g % M) * (it.second % M)) % M) % M;
    m1[g] = (m1[g] + it.second) % M;
  }
  for (auto it : adj[u]) {
    if (it == par) continue;
    dfs(m1, it, u);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  map<long long, long long> m;
  dfs(m, 1);
  cout << ans;
  return 0;
}
