#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool f = false;
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - 48, ch = getchar();
  return f ? -x : x;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
const long long dev = 1e9 + 7;
int n, a = 0;
long long ans = 0, A[100005], V[100005][45];
int cnt[100005], C[100005][45];
struct Way {
  int to, next;
} M[200005];
int W[100005];
long long gcd(long long _, long long __) {
  if (_ && __) return gcd(__, _ % __);
  return __ | _;
}
void sear(int num, int fa) {
  for (int i = 1; i <= cnt[fa]; i++) {
    long long tmp = gcd(V[fa][i], A[num]);
    if (tmp != V[num][cnt[num]])
      V[num][++cnt[num]] = tmp, C[num][cnt[num]] = C[fa][i];
    else
      C[num][cnt[num]] += C[fa][i];
  }
  if (A[num] == 0)
    C[num][0] = C[fa][0] + 1;
  else {
    if (V[num][cnt[num]] == A[num])
      C[num][cnt[num]] += C[fa][0] + 1;
    else
      V[num][++cnt[num]] = A[num], C[num][cnt[num]] = C[fa][0] + 1;
  }
  for (int i = 1; i <= cnt[num]; i++) ans = (ans + V[num][i] * C[num][i]) % dev;
  for (int i = W[num]; i; i = M[i].next)
    if (M[i].to != fa) sear(M[i].to, num);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) A[i] = read();
  for (int i = 1; i < n; i++) {
    int f = read(), t = read();
    M[++a].to = t;
    M[a].next = W[f];
    W[f] = a;
    M[++a].to = f;
    M[a].next = W[t];
    W[t] = a;
  }
  sear(1, 0);
  write(ans);
  return 0;
}
