#include <bits/stdc++.h>
#pragma GCC omptimize("unroll-loops")
#pragma GCC omptimize("KEK")
#pragma GCC optimize("no-stack-protector")
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
long long fpow(long long x, long long y) {
  if (!y) return 1;
  if (y == 1) return x;
  if (y % 2)
    return fpow(x, y - 1) * x;
  else {
    long long d = fpow(x, y / 2);
    return d * d;
  }
}
long long fl(long long len) {
  if (len == 1)
    return 0;
  else
    return fl(len / 2) + 1;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
const int INF32 = 2009000999;
const long long INF64 = 4e18;
const int sz = 1e5 + 11;
const int mod = 1e9 + 7;
int n;
long long beauty[sz], ans;
vector<map<long long, int>> mp;
vector<vector<int>> gr;
void Input() {
  cin >> n;
  gr.resize(n + 1);
  mp.resize(n + 1);
  for (int i = 1; i <= n; i++) cin >> beauty[i];
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
}
void dfs(int v, int last = -1) {
  long long w = beauty[v];
  if (last != -1)
    for (auto i : mp[last]) mp[v][gcd(w, i.first)] += i.second;
  mp[v][w]++;
  for (auto i : mp[v]) {
    ans += i.first * i.second;
    ans %= mod;
  }
  for (auto i : gr[v])
    if (i != last) dfs(i, v);
}
void Solve() {
  Input();
  dfs(1);
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int q = 1;
  while (q--) Solve();
}
