#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  while (b != 0) {
    unsigned long long tmp = a % b;
    a = b;
    b = tmp;
  }
  return a;
}
const int MOD = 1000000007;
bool visit[100001];
int N;
unsigned long long arr[100001], ans;
vector<int> v[100001];
void dfs(int n, map<unsigned long long, int> mp) {
  if (visit[n]) return;
  visit[n] = 1;
  map<unsigned long long, int> m;
  m[arr[n]]++;
  for (auto i : mp) {
    m[gcd(i.first, arr[n])] += i.second;
  }
  for (auto i : m) {
    ans = (ans + i.first * i.second) % MOD;
  }
  for (auto i : v[n]) dfs(i, m);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> arr[i];
  int a, b;
  while (--N) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  map<unsigned long long, int> m;
  dfs(1, m);
  cout << ans;
}
