#include <bits/stdc++.h>
using namespace std;
const long long md = (1e9) + 7;
long long n, vl[100001], to = 0;
vector<vector<int> > adj;
vector<pair<long long, long long> > gd[100001] = {}, tp;
int a, b;
long long gcd(long long a, long long b) { return (b) ? gcd(b, a % b) : a; }
void dfs(int u, int p) {
  if (p != -1) {
    for (int i = 0; i < gd[p].size(); i++) {
      tp.push_back({gcd(gd[p][i].first, vl[u]), gd[p][i].second});
    }
  }
  tp.push_back({vl[u], 1});
  sort(tp.begin(), tp.end());
  long long lg = tp[0].second;
  for (int i = 1; i < tp.size(); i++) {
    if (tp[i].first != tp[i - 1].first) {
      gd[u].push_back({tp[i - 1].first, lg});
      to += (tp[i - 1].first % md * lg) % md;
      to %= md;
      lg = 0;
    }
    lg += tp[i].second;
    lg %= md;
  }
  gd[u].push_back({tp.back().first, lg});
  to += (tp.back().first % md * lg) % md;
  to %= md;
  tp.clear();
  for (auto v : adj[u]) {
    if (v != p) {
      dfs(v, u);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> vl[i];
    adj.push_back(vector<int>());
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    adj[a - 1].push_back(b - 1);
    adj[b - 1].push_back(a - 1);
  }
  dfs(0, -1);
  cout << to << "\n";
  return 0;
}
