#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N;
long long X[100001];
vector<int> adj[100001];
map<long long, long long> mp[100001];
long long ans = 0;
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
void dfs(int node, int par) {
  mp[node][X[node]]++;
  for (int x : adj[node]) {
    if (x != par) {
      for (auto it : mp[node]) mp[x][gcd(it.first, X[x])] += it.second;
      dfs(x, node);
    }
  }
  for (auto it : mp[node]) ans = (ans + it.first * it.second) % 1000000007;
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> X[i];
  for (int i = 1; i < N; i++) {
    int A, B;
    cin >> A >> B;
    adj[A].push_back(B);
    adj[B].push_back(A);
  }
  dfs(1, 1);
  cout << ans << endl;
  return 0;
}
