#include <bits/stdc++.h>
using namespace std;
long long int pos(long long int n) {
  if (n >= 0) {
    return n;
  }
  return -n;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long int a[100005];
bool visited[100005];
map<long long int, long long int> m[100005];
vector<long long int> graph[100005];
long long int answer = 0;
long long int pr = 1000000007;
void dfs(long long int n, long long int p) {
  visited[n] = 1;
  m[n][a[n]]++;
  map<long long int, long long int>::iterator it;
  if (p != 0) {
    for (it = m[p].begin(); it != m[p].end(); it++) {
      m[n][gcd(a[n], it->first)] += it->second;
    }
  }
  for (it = m[n].begin(); it != m[n].end(); it++) {
    answer += it->first * it->second;
    if (answer >= p) {
      answer %= pr;
    }
  }
  for (long long int i = 0; i < graph[n].size(); i++) {
    if (visited[graph[n][i]]) {
      continue;
    }
    dfs(graph[n][i], n);
  }
  return;
}
signed main() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(1, 0);
  cout << answer;
}
