#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.14159265358979323;
const long long int linf = 1000111000111000111LL;
const long long int inf = 1011111111;
const long long int N = 100005;
long long int n, ans;
long long int bty[N];
map<long long int, long long int> mp1[N];
vector<long long int> g[N];
void input() {
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> bty[i];
  for (long long int i = 0; i < n - 1; i++) {
    long long int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void dfs(long long int node, long long int par) {
  mp1[node][bty[node]]++;
  for (auto v : g[node]) {
    if (v == par) continue;
    for (auto it : mp1[node]) {
      long long int ele = it.first;
      long long int freq = it.second;
      long long int cur = gcd(ele, bty[v]);
      mp1[v][cur] += freq;
    }
    dfs(v, node);
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int test = 1;
  while (test--) {
    input();
    dfs(1, 1);
    for (long long int i = 1; i <= n; i++) {
      for (auto it : mp1[i]) {
        long long int ct = (((it.first)) * it.second);
        ans = (ans + ct) % 1000000007;
      }
    }
    cout << ans;
  }
  cerr << '\n'
       << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
