#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int MOD = int(1e9 + 7);
const int N = int(1e5 + 10);
int head[N];
pair<int, int> eg[N * 2];
int tot = 0;
inline void addEdge(int u, int v) {
  eg[tot] = {v, head[u]};
  head[u] = tot++;
}
int n;
long long a[N];
vector<pair<long long, int>> p[N];
void dfs(int u, int pre) {
  p[u].clear();
  p[u].emplace_back(a[u], 1);
  for (const auto &it : p[pre]) {
    long long g = gcd(it.first, a[u]);
    if (p[u].back().first == g) {
      p[u].back().second += it.second;
    } else {
      p[u].emplace_back(g, it.second);
    }
  }
  for (int i = head[u]; ~i; i = eg[i].second) {
    int v = eg[i].first;
    if (v == pre) continue;
    dfs(v, u);
  }
}
void solve() {
  while (cin >> n) {
    memset(head, -1, sizeof(int) * (n + 1));
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      p[i].clear();
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      addEdge(u, v);
      addEdge(v, u);
    }
    dfs(1, 0);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      for (const auto &it : p[i]) (ans += it.first * it.second) %= MOD;
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
