#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long v[100010], spt[25][100010];
vector<int> graph[100010];
int parents[100010], ancestors[25][100010], visited[100010], n, levels[100010],
    lgN;
long long add(long long a, long long b) {
  return ((a % mod) + (b % mod)) % mod;
}
long long mul(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long gcd(long long a, long long b) {
  if (b == 0LL) return a;
  return gcd(b, a % b);
}
void dfs(int node) {
  if (visited[node] == 1) return;
  visited[node] = 1;
  int neighbor;
  for (int i = 0; i < (int)graph[node].size(); i++) {
    neighbor = graph[node][i];
    if (visited[neighbor] == 0) {
      parents[neighbor] = node;
      levels[neighbor] = levels[node] + 1;
      dfs(neighbor);
    }
  }
}
void build() {
  int lg;
  for (lg = 1; (1 << lg) <= n; lg++)
    ;
  lg--;
  lgN = lg;
  for (int j = 0; j <= lg; j++) {
    for (int i = 0; i <= n; i++) ancestors[j][i] = -1;
  }
  for (int i = 2; i <= n; i++) {
    ancestors[0][i] = parents[i];
    spt[0][i] = gcd(v[i], v[parents[i]]);
  }
  for (int j = 1; j <= lg; j++) {
    for (int i = 1; i <= n; i++) {
      if (ancestors[j - 1][i] != -1) {
        ancestors[j][i] = ancestors[j - 1][ancestors[j - 1][i]];
        spt[j][i] = gcd(spt[j - 1][i], spt[j - 1][ancestors[j - 1][i]]);
      }
    }
  }
}
long long solve(int node) {
  long long qtd, ans = 0LL, aux = v[node], last = v[node], minus;
  while (true) {
    qtd = minus = levels[node];
    aux = gcd(aux, v[node]);
    for (int i = lgN; i >= 0; i--) {
      if (ancestors[i][node] == -1) continue;
      if (aux == gcd(aux, spt[i][node])) {
        node = ancestors[i][node];
        minus = levels[node];
      }
    }
    qtd -= (minus - 1LL);
    ans = add(ans, mul(qtd, aux));
    if (node != 1)
      node = ancestors[0][node];
    else
      break;
  }
  return ans;
}
int main() {
  long long ans = 0;
  int n1, n2;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &v[i]);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &n1, &n2);
    graph[n1].push_back(n2);
    graph[n2].push_back(n1);
  }
  parents[1] = -1;
  levels[1] = 0;
  dfs(1);
  build();
  for (int i = 1; i <= n; i++) ans = add(ans, solve(i));
  printf("%lld\n", ans);
  return 0;
}
