#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(1e9 + 1337);
const long long LINF = (long long)(4e18);
const double EPS = (double)(1e-7);
int64_t gcd(int64_t a, int64_t b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
const int64_t MOD = 1000000007;
int64_t add(int64_t a, int64_t b) { return (a + b) % MOD; }
long long mul(int64_t a, int64_t b) { return (a * b) % MOD; }
int n;
vector<int64_t> x;
vector<vector<int> > g;
struct gp {
  int64_t gc;
  int64_t ctr;
};
int64_t ans;
void dfs(int v, int p, const vector<gp>& old_st) {
  vector<gp> st;
  for (auto node : old_st) {
    node.gc = gcd(node.gc, x[v]);
    if (!st.empty() && node.gc == st.back().gc) {
      st.back().ctr += node.ctr;
    } else {
      st.emplace_back(node);
    }
  }
  gp onode{x[v], 1};
  if (!st.empty() && onode.gc == st.back().gc) {
    st.back().ctr += onode.ctr;
  } else {
    st.emplace_back(onode);
  }
  for (const auto& node : st) {
    ans = add(ans, mul(node.gc, node.ctr));
  }
  for (int i = 0; i < (int)g[v].size(); ++i) {
    int to = g[v][i];
    if (to == p) {
      continue;
    }
    dfs(to, v, st);
  }
}
void solve() {
  cin >> n;
  x.resize(n + 1);
  g.resize(n + 1);
  x[0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
  }
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<gp> st;
  dfs(1, 0, st);
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
