#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> edges;
long long n;
set<int> vis;
vector<long long> b;
long long res = 0;
long long MOD = 1000 * 1000 * 1000 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(long long cur, map<long long, long long> cnt) {
  if (vis.count(cur)) return;
  vis.insert(cur);
  map<long long, long long> cnt2;
  cnt[b[cur]]++;
  for (auto it : cnt) {
    long long temp = gcd(it.first, b[cur]);
    res += (temp * it.second) % MOD;
    res %= MOD;
    cnt2[temp] += it.second;
  }
  for (int i : edges[cur]) {
    dfs(i, cnt2);
  }
}
void solve() {
  cin >> n;
  edges.clear();
  edges.resize(n + 1);
  b.clear();
  b.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i < n; i++) {
    int o, t;
    cin >> o >> t;
    edges[o].push_back(t);
    edges[t].push_back(o);
  }
  map<long long, long long> cnt;
  dfs(1, cnt);
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
