#include <bits/stdc++.h>
using namespace std;
const int imax = 1e9 + 7;
const long long lmax = 1e18;
vector<long long> v;
vector<vector<int> > adj;
const long long Mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long dfs(int prev, int cur, map<long long, int> mp) {
  long long ans = 0, val = v[cur];
  map<long long, int> cmp;
  cmp.clear();
  cmp[val]++;
  ans = (ans + val) % Mod;
  for (pair<long long, int> pp : mp) {
    val = gcd(v[cur], pp.first);
    cmp[val] += pp.second;
    ans = (ans + ((val * pp.second) % Mod)) % Mod;
  }
  for (int next : adj[cur]) {
    if (next == prev) continue;
    ans = (ans + dfs(cur, next, cmp)) % Mod;
  }
  return ans;
}
int calc() {
  int n, a, b, i;
  cin >> n;
  v.resize(n);
  adj.clear();
  adj.resize(n, vector<int>(0));
  for (i = 0; i < n; ++i) cin >> v[i];
  for (i = 1; i < n; ++i) {
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  cout << dfs(-1, 0, map<long long, int>());
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  calc();
  cout << endl;
  return 0;
}
