#include <bits/stdc++.h>
using namespace std;
template <typename elemType>
inline void Read(elemType &T) {
  elemType X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  T = (w ? -X : X);
}
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
const int maxn = 100010;
const long long MOD = 1000000007LL;
struct Graph {
  struct edge {
    int Next, to;
  };
  edge G[maxn << 1];
  int head[maxn];
  int cnt;
  Graph() : cnt(2) {}
  void clear(int node_num = 0) {
    cnt = 2;
    if (node_num == 0)
      memset(head, 0, sizeof(head));
    else
      fill(head, head + node_num + 5, 0);
  }
  void add_edge(int u, int v) {
    G[cnt].to = v;
    G[cnt].Next = head[u];
    head[u] = cnt++;
  }
};
Graph G;
long long Value[maxn];
map<long long, long long> Hash[maxn];
long long Ans = 0;
int N;
void DFS(int u, int fa) {
  ++Hash[u][Value[u]];
  for (auto it : Hash[u]) Ans = (Ans + it.first * it.second % MOD) % MOD;
  for (int i = G.head[u]; i; i = G.G[i].Next) {
    int v = G.G[i].to;
    if (v == fa) continue;
    for (auto it : Hash[u]) {
      long long x = GCD(Value[v], it.first);
      Hash[v][x] += it.second;
    }
    DFS(v, u);
  }
  return;
}
int main() {
  Read(N);
  for (register int i = 1; i <= N; ++i) Read(Value[i]);
  for (register int i = 1; i <= N - 1; ++i) {
    int u, v;
    Read(u);
    Read(v);
    G.add_edge(u, v);
    G.add_edge(v, u);
  }
  DFS(1, 0);
  printf("%I64d\n", Ans);
  return 0;
}
