#include <bits/stdc++.h>
using namespace std;
namespace _ {
bool rEOF = 1;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && rEOF &&
                 (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? (rEOF = 0, EOF)
             : *p1++;
}
template <class _T>
inline bool read(_T &num) {
  char c = nc(), f = 1;
  num = 0;
  while (c < '0' || c > '9') c == '-' && (f = -1), c = nc();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = nc();
  return (bool)(num *= f);
}
inline bool need(char &c) {
  return c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c >= 'A' && c <= 'Z';
}
inline bool read_str(char *a) {
  while ((*a = nc()) && need(*a) && rEOF) ++a;
  *a = '\0';
  return rEOF;
}
}  // namespace _
using namespace _;
void file(bool opt) {
  if (opt && fopen("in.txt", "r")) {
    freopen("in.txt", "r", stdin);
  }
}
const int mod = 1e9 + 7;
long long c[100000 + 5];
vector<int> edge[100000 + 5];
map<long long, long long> p[100000 + 5];
long long ans = 0;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
void dfs(int u, int fa) {
  for (auto x : p[fa]) {
    p[u][gcd(c[u], x.first)] += x.second;
    p[u][gcd(c[u], x.first)] %= mod;
  }
  p[u][c[u]]++;
  p[u][c[u]] %= mod;
  for (auto x : p[u]) ans = (ans + (x.first % mod * x.second) % mod) % mod;
  for (auto v : edge[u]) {
    if (v == fa) continue;
    dfs(v, u);
  }
}
int main() {
  file(1);
  int n;
  read(n);
  for (int i = 1; i <= n; i++) read(c[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    read(u), read(v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(1, 0);
  printf("%lld\n", ans);
  return 0;
}
