#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
void dfs(int v, int par, map<long long, int> freq, int& n, vector<long long>& x,
         vector<vector<int>>& g, long long& ans) {
  map<long long, int> next_freq;
  for (auto val : freq) {
    next_freq[gcd(val.first, x[v])] += val.second;
  }
  next_freq[x[v]] += 1;
  for (auto val : next_freq) {
    ans = (ans % MOD + (val.first * val.second) % MOD) % MOD;
  }
  for (int to : g[v]) {
    if (to == par) continue;
    dfs(to, v, next_freq, n, x, g, ans);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed;
  cout.precision(10);
  if (fopen("joke.in", "r")) {
    freopen("joke.in", "r", stdin);
    freopen("joke.out", "w", stdout);
  }
  int n;
  cin >> n;
  vector<long long> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  vector<vector<int>> g(n, vector<int>());
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long ans = 0;
  dfs(0, -1, map<long long, int>(), n, x, g, ans);
  cout << ans;
  return 0;
}
