#include <bits/stdc++.h>
const int maxn = 101000, maxm = 201000;
using namespace std;
struct tnode {
  long long data, fa;
  vector<int> son;
} tree[maxn];
struct ljb {
  int firstEdge[maxn], used[maxn], m, n;
  struct edgeNode {
    int x, v, next;
  } edge[maxm * 2];
  ljb() { memset(this, 0, sizeof(ljb)); }
  inline void append(int op, int ed) {
    m++;
    edge[m].x = ed;
    edge[m].next = firstEdge[op];
    firstEdge[op] = m;
  }
  void dfs(int x) {
    for (int q = firstEdge[x]; q; q = edge[q].next) {
      int v = edge[q].x;
      if (tree[x].fa != v) {
        tree[v].fa = x;
        tree[x].son.push_back(v);
        dfs(v);
      }
    }
  }
} graph;
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  for (long long z = x % y; z; x = y, y = z, z = x % y)
    ;
  return y;
}
long long ans = 0, p = 1000000007;
void dfs(int now, const map<long long, int>& mp) {
  map<long long, int> nmp;
  long long t = 0;
  nmp[tree[now].data] = 1;
  for (const auto& i : mp) {
    nmp[gcd(i.first, tree[now].data)] += i.second;
  }
  for (const auto& i : nmp) {
    (t += i.second * i.first) %= p;
  }
  (ans += t) %= p;
  for (auto k : tree[now].son) {
    dfs(k, nmp);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i += 1) {
    cin >> tree[i].data;
  }
  for (int i = 1; i < n; i += 1) {
    int x, y;
    cin >> x >> y;
    graph.append(x, y), graph.append(y, x);
  }
  graph.dfs(1);
  dfs(1, map<long long, int>());
  cout << (ans % p + p) % p << endl;
  return 0;
}
