#include <bits/stdc++.h>
const long long inf = 1e18 + 44;
const int MAX = 3e5 + 9;
const long long MOD = 1e9 + 7;
const int TOT_PRIMES = 1e6 + 9;
const int MAX_A = 71;
const int LN = 20;
const double eps = 1e-1;
using namespace std;
long long find_gcd(long long a, long long b) {
  if (a <= b) swap(a, b);
  while (b > 0) {
    long long temp = a % b;
    a = b;
    b = temp;
    if (a <= b) swap(a, b);
  }
  return a;
}
map<long long, long long> cnt[MAX];
vector<int> adj[MAX];
long long arr[MAX];
long long res = 0;
void dfs(long long u, long long par) {
  map<long long, long long> tmp;
  tmp = cnt[par];
  cnt[u][arr[u]] = 1;
  for (auto it : tmp) {
    long long now = find_gcd(it.first, arr[u]);
    cnt[u][now] += it.second;
  }
  for (auto it : cnt[u]) {
    res = res + (1ll * (it.first % MOD) * (it.second % MOD)) % MOD;
    res = res % MOD;
  }
  for (auto v : adj[u]) {
    if (par == v) continue;
    dfs(v, u);
  }
}
int main() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0);
  cout << res;
}
