#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int ar[100005];
vector<int> v[100005];
long long int ans;
int dfs(int x, int par, vector<pair<long long int, int> > vc) {
  vector<pair<long long int, int> > vt;
  vt.push_back(make_pair(ar[x], 1));
  long long int gc = ar[x];
  ans = (ans + gc) % 1000000007;
  for (auto it : vc) {
    gc = gcd(gc, it.first);
    ans = (ans + gc * it.second) % 1000000007;
    if (gc == vt[vt.size() - 1].first) {
      vt[vt.size() - 1].second += it.second;
    } else {
      vt.push_back(make_pair(gc, it.second));
    }
  }
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i] == par) continue;
    dfs(v[x][i], x, vt);
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vector<pair<long long int, int> > vc;
  dfs(0, 0, vc);
  cout << ans << endl;
  return 0;
}
