#include <bits/stdc++.h>
using namespace std;
template <class T>
bool rmn(T& a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool rmx(T& a, T b) {
  return a < b ? (a = b, true) : false;
}
const long long INFLL = 0x7f7f7f7f7f7f7f7f, MOD = 1e9 + 7;
const long long INF = 0x7f7f7f7f;
vector<vector<long long>> adj;
vector<long long> vis, color;
long long dx8[] = {0, 1, 1, 1, 0, -1, -1, -1},
          dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx4[] = {0, 1, 0, -1},
          dy4[] = {1, 0, -1, 0};
inline long long mexp(long long x, long long n, long long m = MOD) {
  long long res = 1;
  x %= m;
  while (n) {
    if (n & 1) res = (res * x) % m;
    n >>= 1;
    x = (x * x) % m;
  }
  return res;
}
inline long long gcd(long long a, long long b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  while (a > 0 && b > 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
template <long long MOD>
struct Modular {
  long long value;
  static const long long MOD_value = MOD;
  Modular(long long v = 0) {
    value = v % MOD;
    if (value < 0) value += MOD;
  }
  Modular(long long a, long long b) : value(0) {
    *this += a;
    *this /= b;
  }
  Modular& operator+=(Modular const& b) {
    value += b.value;
    if (value >= MOD) value -= MOD;
    return *this;
  }
  Modular& operator-=(Modular const& b) {
    value -= b.value;
    if (value < 0) value += MOD;
    return *this;
  }
  Modular& operator*=(Modular const& b) {
    value = (long long)value * b.value % MOD;
    return *this;
  }
  friend Modular mexp(Modular a, long long e) {
    Modular res = 1;
    while (e) {
      if (e & 1) res *= a;
      a *= a;
      e >>= 1;
    }
    return res;
  }
  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) {
    return os << a.value;
  }
  friend bool operator==(Modular const& a, Modular const& b) {
    return a.value == b.value;
  }
  friend bool operator!=(Modular const& a, Modular const& b) {
    return a.value != b.value;
  }
};
vector<long long> val;
Modular<MOD> ans = 0;
void dfs(long long u, long long p, unordered_map<long long, long long> cur) {
  unordered_map<long long, long long> nxt;
  cur[0]++;
  for (auto& [n, ct] : cur) {
    long long g = gcd(val[u], n);
    nxt[g] += ct;
    ans += g * ct;
  }
  cur = nxt;
  for (auto v : adj[u]) {
    if (v == p) continue;
    dfs(v, u, cur);
  }
}
int32_t main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cerr << fixed;
  cout << setprecision(10);
  cerr << setprecision(3);
  mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());
  long long n;
  cin >> n;
  val.resize(n);
  for (long long i = 0; i < n; ++i) cin >> val[i];
  adj.resize(n);
  for (long long i = 0; i < n - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  dfs(0, -1, {});
  cout << ans << '\n';
  return 0;
}
