#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m[100005];
long long v[100005];
vector<long long> adj[100005];
long long sol = 0;
const int mod = 1000000007;
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
void dfs(int node, int dad) {
  for (auto x : m[dad]) {
    long long p = gcd(x.first, v[node]);
    m[node][p] += x.second;
  }
  m[node][v[node]]++;
  for (auto x : m[node]) {
    sol = (sol + 1LL * x.first * x.second) % mod;
  }
  for (auto x : adj[node]) {
    if (x != dad) {
      dfs(x, node);
    }
  }
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  cout << sol;
}
