#include <bits/stdc++.h>
using namespace std;
struct Debug {
  int cnt = 0;
  bool on = false;
  char debug[10] = "debug";
  template <class T>
  Debug& operator<<(const T& v) {
    if (on && cnt++ == 0) cerr << "debug: ";
    if (on) cerr << v << ' ';
    return *this;
  }
  Debug& operator<<(ostream& (*pManip)(ostream&)) {
    if (on) cerr << (*pManip);
    cnt = 0;
    return *this;
  }
} debug;
const int MAXN = 1e5 + 20;
const long long mod = 1e9 + 7;
vector<int> graph[MAXN];
int n;
long long a[MAXN];
long long res = 0;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
void dfs(int i, int p, const unordered_map<long long, long long>& mp0) {
  unordered_map<long long, long long> mp;
  for (auto& q : mp0) mp[gcd(a[i], q.first)] += q.second;
  mp[a[i]]++;
  for (auto& q : mp) res = (res + q.first * q.second % mod) % mod;
  for (int j : graph[i]) {
    if (j == p) continue;
    dfs(j, i, mp);
  }
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  if (argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  dfs(0, -1, unordered_map<long long, long long>());
  cout << res << endl;
  return 0;
}
