#include <bits/stdc++.h>
using namespace std;
unsigned long long read() {
  unsigned long long ret = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = (ret << 1) + (ret << 3) + c - 48;
    c = getchar();
  }
  return ret * f;
}
const int maxn = 2e5 + 7;
const unsigned long long mod = 1e9 + 7;
struct asd {
  int u, v, next;
} e[maxn];
int head[maxn], cnt = 1;
void add(int u, int v) {
  e[cnt] = {u, v, head[u]};
  head[u] = cnt++;
}
unsigned long long w[maxn];
unsigned long long ans = 0;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
map<unsigned long long, int> a[maxn];
void dfs(int u, int fa) {
  a[u][w[u]]++;
  for (auto it : a[fa]) {
    a[u][gcd(it.first, w[u])] += it.second;
  }
  int sum = 0;
  for (auto it : a[u]) {
    sum++;
    ans = (ans + it.first % mod * it.second % mod) % mod;
  }
  assert(sum < 100);
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].v;
    if (v != fa) {
      dfs(v, u);
    }
  }
}
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) w[i] = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    add(u, v);
    add(v, u);
  }
  dfs(1, 0);
  cout << ans;
}
