#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> add_pair(pair<long long, long long> a,
                                    pair<long long, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
long long power(long long a, long long b) {
  long long res = 1;
  a = a % ((long long)1e9 + 7);
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % ((long long)1e9 + 7);
      b--;
    }
    a = (a * a) % ((long long)1e9 + 7);
    b >>= 1;
  }
  return res;
}
long long fermat_inv(long long y) { return power(y, ((long long)1e9 + 7) - 2); }
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
long long mul(long long a, long long b) {
  return (a * (b % ((long long)1e9 + 7))) % ((long long)1e9 + 7);
}
long long sub(long long a, long long b) {
  return ((a - b) % ((long long)1e9 + 7) + ((long long)1e9 + 7)) %
         ((long long)1e9 + 7);
}
long long add(long long a, long long b) {
  return ((a + b) % ((long long)1e9 + 7) + ((long long)1e9 + 7)) %
         ((long long)1e9 + 7);
}
vector<vector<long long> > G;
map<long long, long long> m[100005];
vector<long long> b;
long long ans;
void dfs(long long rt, long long par) {
  m[rt][b[rt]]++;
  if (rt != par) {
    for (auto it = (m[par]).begin(); it != (m[par]).end(); it++) {
      m[rt][gcd(b[rt], it->first)] += it->second;
    }
  }
  for (auto it = (m[rt]).begin(); it != (m[rt]).end(); it++) {
    ans = add(ans, mul(it->first, it->second));
  }
  for (auto it = (G[rt]).begin(); it != (G[rt]).end(); it++) {
    if (*it != par) {
      dfs(*it, rt);
    }
  }
}
void solve() {
  long long n, u, v, i;
  cin >> n;
  G = vector<vector<long long> >(n + 1, vector<long long>());
  b = vector<long long>(n + 1);
  for (i = (0); i < (n); i += (1)) cin >> b[i + 1];
  for (i = (0); i < (n - 1); i += (1)) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  ans = 0;
  dfs(1, 1);
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
