#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 1;
const long long mod = 1e9 + 7;
int n;
long long x[maxN];
vector<int> adj[maxN];
map<long long, int> mp[maxN];
long long res = 0;
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
void DFS(int u, int parent) {
  for (auto &k : mp[parent]) {
    mp[u][GCD(x[u], k.first)] += k.second;
  }
  ++mp[u][x[u]];
  for (auto &v : adj[u]) {
    if (v != parent) {
      DFS(v, u);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  DFS(1, 0);
  for (int i = 1; i <= n; ++i) {
    for (auto &k : mp[i]) {
      res += k.first * k.second;
      res %= mod;
    }
  }
  cout << res;
  return 0;
}
