#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
const long long P = 1e9 + 7;
unordered_map<long long, int> f[M];
vector<int> G[M];
long long w[M], res;
int n;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void dfs(int u, int fa) {
  for (auto v : f[fa]) {
    long long x = gcd(v.first, w[u]);
    f[u][x] += v.second;
    x %= P;
    res = (res + 1ll * v.second * x % P) % P;
  }
  res = (res + w[u] % P) % P;
  f[u][w[u]]++;
  for (auto v : G[u]) {
    if (v == fa) continue;
    dfs(v, u);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%lld", &w[i]);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  cout << res << endl;
  return 0;
}
