#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
vector<long long> x;
const int MOD = 1000000007;
long long ans = 0;
long long gcd(long long x, long long y) { return x == 0 ? y : gcd(y % x, x); }
void dfs(int u, int p, vector<pair<long long, int>> count,
         vector<vector<int>> &graph) {
  vector<pair<long long, int>> cur_count;
  for (auto c : count) {
    long long g = gcd(c.first, x[u]);
    if (cur_count.size() != 0 && cur_count.back().first == g) {
      cur_count.back().second += c.second;
    } else {
      cur_count.push_back({g, c.second});
    }
  }
  long long cur_node_value = x[u];
  if (cur_count.size() != 0 && cur_count.back().first == cur_node_value) {
    cur_count.back().second++;
  } else {
    cur_count.push_back({cur_node_value, 1});
  }
  for (auto &c : cur_count) {
    ans = (ans + (c.first * c.second) % MOD) % MOD;
  }
  for (auto &v : graph[u]) {
    if (v != p) {
      dfs(v, u, cur_count, graph);
    }
  }
}
void solve() {
  int n;
  cin >> n;
  x.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  vector<vector<int>> graph(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  vector<pair<long long, int>> count;
  dfs(0, 0, count, graph);
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
