#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &output, const vector<T> &v) {
  if (v.empty()) return output;
  for (int i = 0; i < v.size() - 1; i++) output << v[i] << " ";
  output << v.back();
  return output;
}
template <typename T>
istream &operator>>(istream &input, vector<T> &v) {
  for (auto &i : v) cin >> i;
  return input;
}
long long int gcd(const long long int a, const long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(const long long int a, const long long int b) {
  return (a * b) / gcd(a, b);
}
const int N = 1e5 + 100, mod = 1e9 + 7;
vector<int> g[N];
long long int a[N];
long long int ans = 0;
void dfs(int node, int par, unordered_map<long long int, long long int> &m) {
  unordered_map<long long int, long long int> cur;
  for (auto &i : m) cur[gcd(i.first, a[node])] += i.second;
  cur[a[node]]++;
  for (auto &i : cur) {
    ans += (long long int)i.first * i.second % mod;
    if (ans >= mod) ans -= mod;
  }
  for (auto &i : g[node]) {
    if (i != par) dfs(i, node, cur);
  }
  return;
}
void __sol() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i + 1];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  unordered_map<long long int, long long int> m;
  dfs(1, 0, m);
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  while (tc--) __sol();
  return 0;
}
