#include <bits/stdc++.h>
using namespace std;
const long long int maxN = 1e5, MOD = 1e9 + 7;
vector<long long int> adj[maxN + 10], vals;
long long int N, a, b, ans = 0;
long long int gcd(long long int a, long long int b) {
  return (!b ? a : gcd(b, a % b));
}
void dfs(long long int p, long long int c,
         map<long long int, long long int> mp) {
  ans = (ans + vals[c]) % MOD;
  map<long long int, long long int> mpp;
  long long int g;
  for (auto p : mp) {
    g = gcd(vals[c], p.first);
    mpp[g] += p.second;
    ans = (ans + g * p.second) % MOD;
  }
  mpp[vals[c]]++;
  for (long long int u : adj[c]) {
    if (u == p) continue;
    dfs(c, u, mpp);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> N;
  vals.resize(N);
  for (long long int i = 0; i < N; i++) cin >> vals[i];
  for (long long int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(0, 0, map<long long int, long long int>());
  cout << ans << endl;
}
