#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
long long mod = 1e9 + 7;
long long inf = 1e9;
long double eps = 1e-7;
long double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
vector<vector<int>> g;
vector<long long> a;
long long ans = 0;
void dfs(int v, map<long long, int> m, int p = -1) {
  map<long long, int> cur;
  for (auto i : m) {
    long long v1 = gcd(i.first, a[v]);
    cur[v1] += i.second;
    ans += v1 * i.second % mod;
    ans %= mod;
  }
  cur[a[v]]++;
  ans += a[v];
  ans %= mod;
  for (auto to : g[v]) {
    if (to == p) continue;
    dfs(to, cur, v);
  }
}
int main() {
  int n;
  cin >> n;
  g.resize(n);
  for (int i = 0; i < n; i++) {
    long long t;
    cin >> t;
    a.push_back(t);
  }
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  dfs(0, map<long long, int>());
  cout << ans;
  return 0;
}
