#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
const long long MOD = 1e9 + 7;
long long n, val[MAXN], ans = 0;
vector<int> G[MAXN];
long long gcd(long long x, long long y) { return (x == 0) ? y : gcd(y % x, x); }
void dfs(int u, int p, map<long long, long long> m) {
  map<long long, long long> m2;
  for (auto it : m) {
    long long aux2 = gcd(it.first, val[u]);
    m2[aux2] += it.second;
    ans = (ans + (aux2 * it.second) % MOD) % MOD;
  }
  m2[val[u]]++;
  ans = (ans + val[u]) % MOD;
  for (int viz : G[u]) {
    if (viz == p) continue;
    dfs(viz, u, m2);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &val[i]);
  for (int i = 1; i < n; i++) {
    int xi, yi;
    scanf("%d %d", &xi, &yi);
    G[xi].push_back(yi);
    G[yi].push_back(xi);
  }
  map<long long, long long> inutil;
  dfs(1, 0, inutil);
  printf("%lld\n", ans);
}
