#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
const long long P = 1e9 + 7;
int n;
long long f[N];
vector<int> G[N];
long long res;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int v, map<long long, long long> mp, int par) {
  map<long long, long long> mpi;
  for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();
       it++) {
    long long x = gcd(it->first, f[v]), y = it->second;
    res = (res + x % P * y % P) % P;
    mpi[x] += y;
  }
  res = (res + f[v] % P) % P;
  mpi[f[v]]++;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u == par) continue;
    dfs(u, mpi, v);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", f + i);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  res = 0;
  map<long long, long long> mp;
  dfs(0, mp, -1);
  printf("%lld\n", res);
  return 0;
}
