#include <bits/stdc++.h>
using namespace std;
template <class T = int, class S = T>
T input() {
  T x;
  cin >> (S &)x;
  return x;
}
template <class T>
T gcd(T x, T y) {
  while (y) y ^= x ^= y ^= x %= y;
  return x;
}
struct Node {
  long long x;
  Node *parent;
  vector<Node *> neigh;
  vector<pair<long long, int>> gcdCount;
};
const long long M = 1000000007;
int calc(Node *n) {
  if (n->parent) {
    n->gcdCount.reserve(n->parent->gcdCount.size() + 1);
  }
  n->gcdCount.emplace_back(n->x, 1);
  if (n->parent) {
    for (auto e : n->parent->gcdCount) {
      long long g = gcd(n->x, e.first);
      if (g != n->gcdCount.back().first) {
        n->gcdCount.emplace_back(g, 0);
      }
      n->gcdCount.back().second += e.second;
    }
  }
  long long sumToRoot = 0;
  for (auto e : n->gcdCount) {
    sumToRoot += e.first * e.second;
  }
  long long subtreeSumToRoot = sumToRoot;
  for (Node *v : n->neigh) {
    if (v != n->parent) {
      v->parent = n;
      subtreeSumToRoot += calc(v);
    }
  }
  return subtreeSumToRoot % M;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<Node> nodes;
  int n;
  cin >> n;
  nodes.resize(n);
  for (Node &nd : nodes) {
    cin >> nd.x;
  }
  for (int i = 0; i < n - 1; ++i) {
    int a = input() - 1;
    int b = input() - 1;
    nodes[a].neigh.push_back(&nodes[b]);
    nodes[b].neigh.push_back(&nodes[a]);
  }
  Node *root = &nodes[0];
  root->parent = nullptr;
  cout << calc(root) << endl;
  return 0;
}
