#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:2750050000")
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD1 = 7340033;
const long long BAS = 257;
const long long dy[] = {-1, -1, 1, 1};
const long long dx[] = {-1, 1, -1, 1};
const long long N = 1.5e8;
const double EPS = 1e-11;
const long double PI = 3.14159265358979323846;
const long long SZ = 700;
const long long INF = 1e18 + 213;
const long long MAXN = 5e5 + 10;
long long gcd(long long x, long long y) {
  if (x == -1) return y;
  if (y == -1) return x;
  if (x == 0) return y;
  return gcd(y % x, x);
}
long long n, m, k, a[MAXN], b[MAXN];
long long t[MAXN];
void upd(int v, int tl, int tr, int pos, long long x) {
  if (tl == tr) {
    t[v] = x;
  } else {
    int tm = tl + tr >> 1;
    if (pos <= tm)
      upd(2 * v + 1, tl, tm, pos, x);
    else
      upd(2 * v + 2, tm + 1, tr, pos, x);
    t[v] = gcd(t[2 * v + 1], t[2 * v + 2]);
  }
}
long long ask(int v, int tl, int tr, int le, int ri) {
  if (tl > ri || tr < le) return -1;
  if (tl >= le && tr <= ri) return t[v];
  int tm = tl + tr >> 1;
  return gcd(ask(2 * v + 1, tl, tm, le, ri),
             ask(2 * v + 2, tm + 1, tr, le, ri));
}
long long deep(int v, int tl, int tr, long long X) {
  if (tl == tr) {
    return tl;
  }
  int tm = tl + tr >> 1;
  if (gcd(t[2 * v + 2], X) == X)
    return (deep(2 * v + 1, tl, tm, X));
  else
    return deep(2 * v + 2, tm + 1, tr, X);
}
long long answer = 0;
vector<int> g[MAXN];
bool us[MAXN];
int iter = 0;
long long x[MAXN];
void dfs(int v) {
  us[v] = 1;
  upd(0, 0, n - 1, iter, x[v]);
  int le = 0, ri = iter;
  while (ri >= 0) {
    int bl = -1, br = ri;
    long long cur = ask(0, 0, n - 1, br, iter);
    br = deep(0, 0, n - 1, cur);
    long long w = ask(0, 0, n - 1, br, iter);
    if (w != cur) br++;
    answer += (ri - br + 1) * cur % MOD;
    ri = br - 1;
  }
  iter++;
  for (int to : g[v])
    if (!us[to]) dfs(to);
  iter--;
  upd(0, 0, n - 1, iter, -1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  srand(89398);
  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--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0);
  cout << answer % MOD;
}
