#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
long long gcd(long long x, long long y) { return x == 0 ? y : gcd(y % x, x); }
class SegTree {
  int n;
  vector<long long> t;

 public:
  SegTree(int n) : n(n) { t.resize(4 * n); }
  long long _query(int v, int l, int r, int tl, int tr) {
    if (tl > tr) return 0;
    if (tl == l && tr == r) return t[v];
    int mid = (l + r) / 2;
    return gcd(_query(2 * v + 1, l, mid, tl, min(tr, mid)),
               _query(2 * v + 2, mid + 1, r, max(tl, mid + 1), tr));
  }
  long long query(int tl, int tr) { return _query(0, 0, n - 1, tl, tr); }
  void _update(int v, int l, int r, int pos, long long val) {
    if (l == pos && r == pos) {
      t[v] = val;
      return;
    }
    int mid = (l + r) / 2;
    if (pos <= mid)
      _update(2 * v + 1, l, mid, pos, val);
    else
      _update(2 * v + 2, mid + 1, r, pos, val);
    t[v] = gcd(t[2 * v + 1], t[2 * v + 2]);
  }
  void update(int pos, long long val) { _update(0, 0, n - 1, pos, val); }
};
const int N = 1E5 + 100;
long long x[N];
vector<int> adj[N];
SegTree st(N);
int res;
const int MOD = 1E9 + 7;
map<long long, int> cnt;
void DFS(int u, int p, int d) {
  map<long long, int> new_cnt;
  new_cnt[x[u]] += 1;
  for (auto pp : cnt) {
    new_cnt[gcd(pp.first, x[u])] += pp.second;
  }
  for (auto pp : new_cnt) {
    res = (res + pp.first * pp.second % MOD) % MOD;
  }
  swap(cnt, new_cnt);
  for (int v : adj[u]) {
    if (v == p) continue;
    DFS(v, u, d + 1);
  }
  swap(cnt, new_cnt);
}
int main() {
  fast();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DFS(0, -1, 0);
  cout << res << '\n';
}
