#include <bits/stdc++.h>
using namespace std;
const int NN = 100 * 1000 + 5;
map<pair<pair<int, long long>, int>, long long> dp;
vector<int> adj[NN];
vector<long long> x;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int mod = (int)1e9 + 7;
int rec(int node, int parent, long long g, int state) {
  pair<pair<int, long long>, int> p = make_pair(make_pair(node, g), state);
  if (dp.find(p) != dp.end()) return dp[p];
  long long& res = dp[p];
  res = gcd(g, x[node]);
  res %= mod;
  long long new_g = gcd(g, x[node]);
  for (int child : adj[node]) {
    if (child == parent) continue;
    if (state == 0) {
      res += rec(child, node, g, 0);
      res %= mod;
    }
    res += rec(child, node, new_g, 1);
    res %= mod;
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  x.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long ans = rec(0, -1, 0, 0);
  cout << ans << endl;
}
