#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
unordered_map<ll, int> *cnt[N];
vector<int> g[N];
ll val[N];
int sol[N];
int sz[N];
int ans = 0;

int add(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a + b) % mod;
}

int mul(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a * b) % mod;
}

void getsz(int v, int p){
    sz[v] = 1;
    for(auto u : g[v])
        if(u != p){
            getsz(u, v);
            sz[v] += sz[u];
        }
}

void dfs(int node, int parent)
{
    if(val[node] == 0)
    {
        int mx = -1, bigChild = -1;
        for(auto u : g[node])
            if(u != parent){
                dfs(u, node);
                if(sz[u] > mx)
                    mx = sz[u], bigChild = u;
                sol[node] = add(sol[node], sol[u]);
            }
        if(bigChild != -1)
            cnt[node] = cnt[bigChild];
        else
            cnt[node] = new unordered_map<ll, int> ();
        (*cnt[node])[val[node]] ++;
        for(auto u : g[node])
            if(u != parent && u != bigChild){
                for(auto x : *cnt[u])
                    (*cnt[node])[x.first] += x.second;
                delete cnt[u];
            }
    }
    else
    {
        int mx = -1, bigChild = -1;
        for(auto u : g[node])
            if(u != parent){
                dfs(u, node);
                if(sz[u] > mx)
                    mx = sz[u], bigChild = u;
            }
        if(bigChild != -1)
            cnt[node] = cnt[bigChild];
        else
            cnt[node] = new unordered_map<ll, int> ();
        (*cnt[node])[val[node]] ++;
        for(auto u : g[node])
            if(u != parent && u != bigChild){
                for(auto x : *cnt[u])
                    (*cnt[node])[x.first] += x.second;
                delete cnt[u];
            }
        unordered_map<ll, int> mp;
        for(auto &x: *cnt[node])
            mp[__gcd(x.first, val[node])] += x.second;
        (*cnt[node]).clear();
        for(auto &x: mp)
            (*cnt[node])[x.first] = x.second;
        for(auto &x: *cnt[node])
            sol[node] = add(sol[node], mul(x.first == 0? val[node] : x.first, x.second));
    }
    ans = add(ans, sol[node]);
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    for(int i = 1; i <= n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    getsz(1, 1);
    dfs(1, 1);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
vector<int> g[N];
ll val[N];
map<ll, int> mp;
int ans = 0;

int add(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a + b) % mod;
}

int mul(ll a, ll b)
{
    a %= mod;
    b %= mod;
    return (a * b) % mod;
}

void dfs(int node, int parent)
{
    map<ll, int> new_mp;
    map<ll, int> prev_mp = mp;
    for(auto &x: mp)
        new_mp[__gcd(val[node], x.first)] += x.second;
    new_mp[val[node]]++;
    mp = new_mp;
    for(auto &x: mp)
        ans = add(ans, mul(x.first == 0 ? val[node] : x.first, x.second));
    for(auto &new_node: g[node])
    {
        if(new_node != parent)
            dfs(new_node, node);
    }
    mp = prev_mp;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    for(int i = 1; i <= n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 1);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
vector<int> g[N];
ll val[N];
map<ll, int> mp;
int ans = 0;

int add(int a, int b)
{
    return (a + b) % mod;
}

int mul(int a, int b)
{
    return (1ll * a * b) % mod;
}

void dfs(int node, int parent)
{
    map<ll, int> prev_mp = mp;
    mp.clear();
    for(auto &x: prev_mp)
        mp[__gcd(val[node], x.first)] += x.second;
    mp[val[node]]++;
    for(auto &x: mp)
        ans = add(ans, mul(x.first == 0 ? val[node] : x.first, x.second));
    for(auto &new_node: g[node])
    {
        if(new_node != parent)
            dfs(new_node, node);
    }
    mp = prev_mp;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> val[i];
    for(int i = 1; i <= n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 1);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll mod1 = 1e8;

ll power(ll a, ll b, ll c) {
	ll ret = 1;
	while(b > 0) {
		if(b%2 == 1)
			ret = (ret * a)%c;
		b /= 2;
		a = (a * a)%c;
	}
	return ret;
}

int n;
ll beauty[N], ans = 0;
vector <int> adj[N];

vector <pair <ll, int> > dfs(int id, int par) {

	map <ll, int> ma;
	ma[beauty[id]] = 1;

	for(auto it : adj[id]) {
		if(it == par) continue;
		vector <pair <ll, int> > res = dfs(it, id);

		for(auto it : res) {
			ma[__gcd(it.ff, beauty[id])] += it.ss;
 		}
	}

	vector <pair<ll, int> > ret;

	for(auto it : ma) {
		ans += it.ss * it.ff;
		// cout << it.ff << " " << it.ss << " " << id << endl;
		ret.pb({it.ff, it.ss});
	}

	return ret;
}

int main() {

	cin >> n;

	for(int i=1;i<=n;i++) {
		cin >> beauty[i];
	}

	for(int i=0;i<n-1;i++) {
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(1, -1);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll mod1 = 1e8;

ll power(ll a, ll b, ll c) {
	ll ret = 1;
	while(b > 0) {
		if(b%2 == 1)
			ret = (ret * a)%c;
		b /= 2;
		a = (a * a)%c;
	}
	return ret;
}

int n;
ll beauty[N];
int ans = 0;
vector <int> adj[N];

vector <pair <ll, int> > dfs(int id, int par) {

	map <ll, int> ma;
	ma[beauty[id]] = 1;

	for(auto it : adj[id]) {
		if(it == par) continue;
		vector <pair <ll, int> > res = dfs(it, id);

		for(auto it : res) {
			ma[__gcd(it.ff, beauty[id])] += it.ss;
 		}
	}

	vector <pair<ll, int> > ret;

	for(auto it : ma) {
		ans += ((ll)it.ss * (ll)it.ff)%mod;
		// cout << it.ff << " " << it.ss << " " << id << endl;
		ret.pb({it.ff, it.ss});
	}

	ans %= mod;

	return ret;
}

int main() {

	fast_io;
	cin >> n;

	for(int i=1;i<=n;i++) {
		cin >> beauty[i];
	}

	for(int i=0;i<n-1;i++) {
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(1, -1);

	cout << ans%mod << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll mod1 = 1e8;

ll power(ll a, ll b, ll c) {
	ll ret = 1;
	while(b > 0) {
		if(b%2 == 1)
			ret = (ret * a)%c;
		b /= 2;
		a = (a * a)%c;
	}
	return ret;
}

int n;
ll beauty[N];
int ans = 0;
vector <int> adj[N];

vector <pair <ll, int> > dfs(int id, int par) {

	map <ll, int> ma;
	ma[beauty[id]] = 1;

	for(auto it : adj[id]) {
		if(it == par) continue;
		vector <pair <ll, int> > res = dfs(it, id);

		for(auto it : res) {
			ma[__gcd(it.ff, beauty[id])] += it.ss;
 		}
	}

	vector <pair<ll, int> > ret;

	for(auto it : ma) {
		ans = (ans + (ll)it.ss * (ll)it.ff)%mod;
		// cout << it.ff << " " << it.ss << " " << id << endl;
		ret.pb({it.ff, it.ss});
	}

	ans %= mod;

	return ret;
}

int main() {

	fast_io;
	cin >> n;

	for(int i=1;i<=n;i++) {
		cin >> beauty[i];
	}

	for(int i=0;i<n-1;i++) {
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(1, -1);

	cout << ans%mod << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll mod1 = 1e8;

ll power(ll a, ll b, ll c) {
	ll ret = 1;
	while(b > 0) {
		if(b%2 == 1)
			ret = (ret * a)%c;
		b /= 2;
		a = (a * a)%c;
	}
	return ret;
}

int n;
ll beauty[N];
int ans = 0;
vector <int> adj[N];
map <ll, int> ma[N];

void dfs(int id, int par) {

	ma[id][beauty[id]] = 1;

	if(ma[par].size() > 0)
		for(auto it : ma[par]) {
			ma[id][__gcd(beauty[id], it.ff)] += it.ss;
		}

	for(auto it : ma[id]) {
		ans = (ans + ((ll)it.ff * (ll)it.ss))%mod;
	}

	for(auto it : adj[id]) {
		if(it == par) continue;
		dfs(it, id);
	}

}

int main() {

	fast_io;
	cin >> n;

	for(int i=1;i<=n;i++) {
		cin >> beauty[i];
	}

	for(int i=0;i<n-1;i++) {
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(1, -1);

	cout << ans%mod << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll mod1 = 1e8;

ll power(ll a, ll b, ll c) {
	ll ret = 1;
	while(b > 0) {
		if(b%2 == 1)
			ret = (ret * a)%c;
		b /= 2;
		a = (a * a)%c;
	}
	return ret;
}

int n;
ll beauty[N], ans = 0;
vector <int> adj[N];

vector <pair <ll, int> > dfs(int id, int par) {

	map <ll, int> ma;
	ma[beauty[id]] = 1;

	for(auto it : adj[id]) {
		if(it == par) continue;
		vector <pair <ll, int> > res = dfs(it, id);

		for(auto it : res) {
			ma[__gcd(it.ff, beauty[id])] += it.ss;
 		}
	}

	vector <pair<ll, int> > ret;

	for(auto it : ma) {
		ans += (it.ss * it.ff)%mod;
		// cout << it.ff << " " << it.ss << " " << id << endl;
		ret.pb({it.ff, it.ss});
	}

	ans %= mod;

	return ret;
}

int main() {

	cin >> n;

	for(int i=1;i<=n;i++) {
		cin >> beauty[i];
	}

	for(int i=0;i<n-1;i++) {
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(1, -1);

	cout << ans%mod << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

std::vector<unsigned long long> krasa;
std::vector<std::vector<int>> g;

unsigned long long gcd( unsigned long long a, unsigned long long b )
{
    if( b == 0 )
        return a;
    else
        return gcd( b, a % b );
}

unsigned long long sum = 0;
unsigned long long mod = 1000000007;

std::list<unsigned long long> Go( int v, int p )
{
    std::list<unsigned long long> res;

    res.push_back(krasa[v]);
    sum = ( sum + res.back()%mod )%mod;

    for( int i = 0; i < g[v].size(); i++ )
    {
        if( g[v][i] == p )
        {
            continue;
        }

        std::list<unsigned long long> child_res = Go( g[v][i], v );

        for( auto it = child_res.begin(); it != child_res.end(); it++ )
        {
            res.push_back( gcd( krasa[v], *it ) );
            sum = ( sum + res.back()%mod )%mod;
        }
    }

    return res;
}

int main()
{
    int n;
    cin >> n;

    krasa.resize(n);
    for( int i = 0; i < n; i++ )
    {
        scanf( "%I64d", &krasa[i] );
    }

    g.resize(n);
    for( int i = 0; i < n-1; i++ )
    {
        int a, b;
        scanf( "%d%d", &a, &b );
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    Go( 0, 0 );

    cout << sum << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

std::vector<unsigned long long> krasa;
std::vector<std::vector<int>> g;

unsigned long long gcd( unsigned long long a, unsigned long long b )
{
    if( b == 0 )
        return a;
    else
        return gcd( b, a % b );
}

unsigned long long sum = 0;
unsigned long long mod = 1000000007;

void Go( int v, int p, std::map<unsigned long long,int>& res )
{
    res[krasa[v]]++;
    sum = ( sum + krasa[v]%mod )%mod;

    std::map<unsigned long long,int> child_res;

    for( int i = 0; i < g[v].size(); i++ )
    {
        if( g[v][i] == p )
        {
            continue;
        }

        Go( g[v][i], v, child_res );
    }

    for( auto it = child_res.begin(); it != child_res.end(); it++ )
    {
        unsigned long long child_gcd = gcd( krasa[v], it->first );
        res[child_gcd] += it->second;
        sum = ( sum + ( child_gcd%mod ) * it->second )%mod;
    }

    return;
}

int main()
{
    int n;
    cin >> n;

    krasa.resize(n);
    for( int i = 0; i < n; i++ )
    {
        scanf( "%I64d", &krasa[i] );
    }

    g.resize(n);
    for( int i = 0; i < n-1; i++ )
    {
        int a, b;
        scanf( "%d%d", &a, &b );
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    std::map<unsigned long long,int> res;
    Go( 0, 0, res );

    cout << sum << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

std::vector<unsigned long long> krasa;
std::vector<std::vector<int>> g;

unsigned long long gcd( unsigned long long a, unsigned long long b )
{
    if( b == 0 )
        return a;
    else
        return gcd( b, a % b );
}

unsigned long long sum = 0;
unsigned long long mod = 1000000007;

std::map<unsigned long long,int> Go( int v, int p )
{
    std::map<unsigned long long,int> res;

    res[krasa[v]]++;
    sum = ( sum + krasa[v]%mod )%mod;

    for( int i = 0; i < g[v].size(); i++ )
    {
        if( g[v][i] == p )
        {
            continue;
        }

        std::map<unsigned long long,int> child_res = Go( g[v][i], v );

        for( auto it = child_res.begin(); it != child_res.end(); it++ )
        {
            unsigned long long child_gcd = gcd( krasa[v], it->first );
            res[child_gcd] += it->second;
            sum = ( sum + ( child_gcd%mod ) * it->second )%mod;
        }
    }

    return res;
}

int main()
{
    int n;
    cin >> n;

    krasa.resize(n);
    for( int i = 0; i < n; i++ )
    {
        scanf( "%I64d", &krasa[i] );
    }

    g.resize(n);
    for( int i = 0; i < n-1; i++ )
    {
        int a, b;
        scanf( "%d%d", &a, &b );
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    Go( 0, 0 );

    cout << sum << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

std::vector<unsigned long long> krasa;
std::vector<std::vector<int>> g;

unsigned long long gcd( unsigned long long a, unsigned long long b )
{
    if( b == 0 )
        return a;
    else
        return gcd( b, a % b );
}

unsigned long long sum = 0;
unsigned long long mod = 1000000007;

std::list<unsigned long long> Go( int v, int p )
{
    std::list<unsigned long long> res;

    res.push_back(krasa[v]);
    sum = ( sum + res.back()%mod )%mod;

    for( int i = 0; i < g[v].size(); i++ )
    {
        if( g[v][i] == p )
        {
            continue;
        }

        std::list<unsigned long long> child_res = Go( g[v][i], v );

        for( auto it = child_res.begin(); it != child_res.end(); it++ )
        {
            res.push_back( gcd( krasa[v], *it ) );
            sum = ( sum + res.back()%mod )%mod;
        }
    }

    return res;
}

int main()
{
    int n;
    cin >> n;

    krasa.resize(n);
    for( int i = 0; i < n; i++ )
    {
        scanf( "%I64d", &krasa[i] );
    }

    g.resize(n);
    for( int i = 0; i < n-1; i++ )
    {
        int a, b;
        scanf( "%d%d", &a, &b );
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    Go( 0, 0 );

    cout << sum << endl;
    getchar();

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

std::vector<unsigned long long> krasa;
std::vector<std::vector<int>> g;

unsigned long long gcd( unsigned long long a, unsigned long long b )
{
    if( b == 0 )
        return a;
    else
        return gcd( b, a % b );
}

unsigned long long sum = 0;
unsigned long long mod = 1000000007;

void Go( int v, int p, const std::map<unsigned long long,int>& p_res )
{
    std::map<unsigned long long,int> res;

    res[krasa[v]]++;
    sum = ( sum + krasa[v]%mod )%mod;

    for( auto it = p_res.begin(); it != p_res.end(); it++ )
    {
        unsigned long long child_gcd = gcd( krasa[v], it->first );
        res[child_gcd] += it->second;
        sum = ( sum + ( child_gcd%mod ) * it->second )%mod;
    }

    for( int i = 0; i < g[v].size(); i++ )
    {
        if( g[v][i] == p )
        {
            continue;
        }

        Go( g[v][i], v, res );
    }

    return;
}

int main()
{
    int n;
    cin >> n;

    krasa.resize(n);
    for( int i = 0; i < n; i++ )
    {
        scanf( "%I64d", &krasa[i] );
    }

    g.resize(n);
    for( int i = 0; i < n-1; i++ )
    {
        int a, b;
        scanf( "%d%d", &a, &b );
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    std::map<unsigned long long,int> res;
    Go( 0, 0, res );

    cout << sum << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

std::vector<unsigned long long> krasa;
std::vector<std::vector<int>> g;

std::map<std::pair<unsigned long long,unsigned long long>,unsigned long long> gcd_cache;

unsigned long long gcd( unsigned long long a, unsigned long long b )
{
    std::pair<unsigned long long,unsigned long long> p( a, b);
    if( a > b )
    {
        swap( p.first, p.second );
    }

    auto it = gcd_cache.find(p);
    if( it != gcd_cache.end() )
    {
        return it->second;
    }

    unsigned long long res;
    if( b == 0 )
        return a;
    else
        res = gcd( b, a % b );

    gcd_cache[p] = res;
    return res;
}

unsigned long long sum = 0;
unsigned long long mod = 1000000007;

std::map<unsigned long long,int> Go( int v, int p )
{
    std::map<unsigned long long,int> res;

    res[krasa[v]]++;
    sum = ( sum + krasa[v]%mod )%mod;

    for( int i = 0; i < g[v].size(); i++ )
    {
        if( g[v][i] == p )
        {
            continue;
        }

        std::map<unsigned long long,int> child_res = Go( g[v][i], v );

        for( auto it = child_res.begin(); it != child_res.end(); it++ )
        {
            unsigned long long child_gcd = gcd( krasa[v], it->first );
            res[child_gcd] += it->second;
            sum = ( sum + ( child_gcd%mod ) * it->second )%mod;
        }
    }

    return res;
}

int main()
{
    int n;
    cin >> n;

    krasa.resize(n);
    for( int i = 0; i < n; i++ )
    {
        scanf( "%I64d", &krasa[i] );
    }

    g.resize(n);
    for( int i = 0; i < n-1; i++ )
    {
        int a, b;
        scanf( "%d%d", &a, &b );
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    Go( 0, 0 );

    cout << sum << endl;

    return 0;
}


/// I won't go back on my words ... that's my ninja way !!!
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5 ,mod = 1e9+7 ;
int n ,u ,v ;
long long x[N] ;
vector<int> adj[N] ;

long long seg[1<<20] ;
void update(int i,long long v,int ni=0,int ns=0,int ne=n-1){
    if(ne<i || ns>i || ns>ne) return ;
    if(ns==ne){
        if(ns==i) seg[ni] = v ;
        return ;
    }
    int l = ni*2+1 ,r = l+1 ,mid = (ns+ne)/2 ;
    update(i,v,l,ns,mid);
    update(i,v,r,mid+1,ne);
    seg[ni] = __gcd(seg[l],seg[r]);
}
long long g(int qs,int qe,int ni=0,int ns=0,int ne=n-1){
    if(ne<qs || ns>qe || ns>ne) return 0;
    if(ns>=qs && ne<=qe) return seg[ni] ;
    int l = ni*2+1 ,r = l+1 ,mid = (ns+ne)/2 ;
    return __gcd(g(qs,qe,l,ns,mid) ,g(qs,qe,r,mid+1,ne));
}
long long dfs(int p,int gp,int i){
    update(i,x[p]);
    long long ret = 0 ;
    for(int ch:adj[p]){
        if(ch==gp)continue;
        ret = (ret + dfs(ch,p,i+1))%mod;
    }
    int to = i ;
    while(to>=0){
        int st = 0 ,en = to ;
        long long gg = g(to,i) ;
        while(st<en){
            int mid = (st+en)/2;
            if(g(mid,i)==gg)en=mid;
            else st = mid+1 ;
        }
        ret = (ret + 1ll * (to+1-st)%mod * gg%mod )%mod;
        to = st-1;
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%lld",x+i);
    for(int i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    printf("%lld",dfs(1,1,0));
    return 0;
}


/// I won't go back on my words ... that's my ninja way !!!
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5 ,mod = 1e9+7 ;
int n ,u ,v ;
long long x[N] ;
vector<int> adj[N] ;

long long seg[1<<20] ,mem[N] ;
int vis[N] ,vid ;

void update(int i,long long v,int ni=0,int ns=0,int ne=n-1){
    if(ne<i || ns>i || ns>ne) return ;
    if(ns==ne){
        if(ns==i) seg[ni] = v ;
        return ;
    }
    int l = ni*2+1 ,r = l+1 ,mid = (ns+ne)/2 ;
    update(i,v,l,ns,mid);
    update(i,v,r,mid+1,ne);
    seg[ni] = __gcd(seg[l],seg[r]);
}
long long g(int qs,int qe,int ni=0,int ns=0,int ne=n-1){
    if(vis[qs]==vid) return mem[qs] ;
    if(ne<qs || ns>qe || ns>ne) return 0;
    if(ns>=qs && ne<=qe) return seg[ni] ;
    int l = ni*2+1 ,r = l+1 ,mid = (ns+ne)/2 ;
    return __gcd(g(qs,qe,l,ns,mid) ,g(qs,qe,r,mid+1,ne));
}
long long dfs(int p,int gp,int i){
    ++vid ;
    update(i,x[p]);
    long long ret = 0 ;
    for(int ch:adj[p]){
        if(ch==gp)continue;
        ret = (ret + dfs(ch,p,i+1))%mod;
    }
    ++vid ;
    int to = i ;
    while(to>=0){
        int st = 0 ,en = to ;
        long long gg = g(to,i) ;
        vis[to] = vid ;
        mem[to] = gg ;
        while(st<en){
            int mid = (st+en)/2;
            long long xx = g(mid,i) ;
            vis[mid] = vid ;
            mem[mid] = xx ;
            if(xx==gg) en=mid;
            else st = mid+1 ;
        }
        ret = (ret + 1ll * (to+1-st)%mod * gg%mod )%mod;
        to = st-1;
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%lld",x+i);
    for(int i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    printf("%lld",dfs(1,1,0));
    return 0;
}


/// I won't go back on my words ... that's my ninja way !!!
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5 ,mod = 1e9+7 ;
int n ,u ,v ;
long long x[N] ;
vector<int> adj[N] ;

long long seg[1<<20] ;
void update(int i,long long v,int ni=0,int ns=0,int ne=N-1){
    if(ne<i || ns>i || ns>ne) return ;
    if(ns==ne){
        if(ns==i) seg[ni] = v ;
        return ;
    }
    int l = ni*2+1 ,r = l+1 ,mid = (ns+ne)/2 ;
    update(i,v,l,ns,mid);
    update(i,v,r,mid+1,ne);
    seg[ni] = __gcd(seg[l],seg[r]);
}
long long g(int qs,int qe,int ni=0,int ns=0,int ne=N-1){
    if(ne<qs || ns>qe || ns>ne) return 0;
    if(ns>=qs && ne<=qe) return seg[ni] ;
    int l = ni*2+1 ,r = l+1 ,mid = (ns+ne)/2 ;
    return __gcd(g(qs,qe,l,ns,mid) ,g(qs,qe,r,mid+1,ne));
}
long long dfs(int p,int gp,int i){
    update(i,x[p]);
    long long ret = 0 ;
    for(int ch:adj[p]){
        if(ch==gp)continue;
        ret = (ret + dfs(ch,p,i+1))%mod;
    }
    int to = i ;
    while(to>=0){
        int st = 0 ,en = to ;
        while(st<en){
            int mid = (st+en)/2;
            if(g(mid,i)==g(to,i))en=mid;
            else st = mid+1 ;
        }
        ret = (ret + 1ll * (to+1-st)%mod * g(to,i)%mod )%mod;
        to = st-1;
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%lld",x+i);
    for(int i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    printf("%lld",dfs(1,1,0));
    return 0;
}


/// I won't go back on my words ... that's my ninja way !!!
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5 ,mod = 1e9+7 ;
int nn ,n ,u ,v ;
long long x[N] ;
vector<int> adj[N] ;

vector<int> vec;

long long spars[20][N] ;
long long LG[N] ;
void build(){
    LG[0] = -1 ;
    for(long long i=0;i<nn;++i){
        LG[i+1] = LG[i] + !(i&(i+1)) ;
        spars[0][i] = x[vec[i]] ;
    }
    for(long long lg = 1 ;(1<<lg)<=nn ;++lg){
        for(long long i =0;i+(1<<lg)<=nn;++i){
            long long a = spars[lg-1][i] ;
            long long b = spars[lg-1][i+(1<<(lg-1))] ;
            spars[lg][i] = __gcd(a,b);
        }
    }
}
long long g(long long s,long long e){
    if(s>e)swap(s,e) ;
    long long siz = e - s + 1 ;
    long long lg = LG[siz] ;
    long long a = spars[lg][s] ;
    long long b = spars[lg][e-(1<<lg)+1] ;
    return __gcd(a,b);
}

long long dfs(int p,int gp){
    vec.push_back(p);
    long long ret = 0 ;
    for(int ch:adj[p]){
        if(ch==gp)continue;
        ret = (ret + dfs(ch,p))%mod;
    }
    int to = vec.size()-1 ;
    nn = vec.size();
    build();
    while(to>=0){
        int st = 0 ,en = to ;
        while(st<en){
            int mid = (st+en)/2;
            if(g(mid,vec.size()-1)==g(to,vec.size()-1))en=mid;
            else st = mid+1 ;
        }
        ret = (ret + 1ll * (vec.size()-st) %mod * g(to,vec.size()-1) %mod )%mod;
        to = st-1;
    }
    vec.pop_back();
    return ret;
}
int main(){
    scanf("%d",&n);
    int m = n-1 ;
    for(int i=1;i<=n;++i)scanf("%lld",x+i);
    while(m--){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    cout << dfs(1,1);
    return 0;
}


/// I won't go back on my words ... that's my ninja way !!!
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5 ,mod = 1e9+7 ;
int n ,u ,v ;
long long x[N] ;
vector<int> adj[N] ;
long long dfs(int p,int gp,map<long long,int> cur){
    map<long long,int> cnt ;
    ++cnt[x[p]] ;
    for(auto go:cur) cnt[__gcd(go.first,x[p])] += go.second ;
    long long ret = 0 ;
    for(auto go:cnt) ret = (ret + 1ll*go.first%mod*go.second%mod)%mod ;
    for(int ch:adj[p]){
        if(ch==gp)continue;
        ret = (ret + dfs(ch,p,cnt))%mod;
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%lld",x+i);
    for(int i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    map<long long,int> tmp ;
    printf("%lld",dfs(1,1,tmp));
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>

const int N = 1e5;

using ll = long long;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll val[N + 5][55], thd[N + 5][55], ans;

struct edge {
    int nxt, to;
} E[N << 1];
int hd[N + 5], etot;
int n;
int fa[N + 5], dep[N + 5], ptr[N + 5];

void addedge(int a, int b) {
    E[++ etot].to = b; E[etot].nxt = hd[a]; hd[a] = etot;
    E[++ etot].to = a; E[etot].nxt = hd[b]; hd[b] = etot;
}

void dfs(int u) {
    //for (int i;)

    thd[u][0] = dep[u];
    thd[u][1] = dep[u] - 1;
    ptr[u] = 1;
    if (fa[u]) {
        int f = fa[u];
        for (int i = 1; i <= ptr[f]; i ++) {
            ll g = gcd(val[u][1], val[f][i]);
            if (g == val[u][ptr[u]]) thd[u][ptr[u]] = thd[f][i];
            else val[u][++ ptr[u]] = g, thd[u][ptr[u]] = thd[f][i];
        }
    }

    for (int i = hd[u]; i; i = E[i].nxt) {
        int to = E[i].to;
        if (to == fa[u]) continue ;
        dep[to] = dep[u] + 1;
        fa[to] = u;
        dfs(to);
    }

    for (int i = 1; i <= ptr[u]; i ++)
        ans += val[u][i] * (thd[u][i - 1] - thd[u][i]);
}

int main() {

    scanf("%d", &n);
    for (int i = 1; i <= n; i ++)
        scanf("%I64d", &val[i][1]);
    for (int i = 1; i < n; i ++) {
        int a, b; scanf("%d%d", &a, &b);
        addedge(a, b);
    }

    dep[1] = 1, fa[1] = 0;

    dfs(1);

    printf("%I64d", ans);

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>

const int N = 1e5;

using ll = long long;

const int mod = 1e9 + 7;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll val[N + 5][55], thd[N + 5][55], ans;

struct edge {
    int nxt, to;
} E[N << 1];
int hd[N + 5], etot;
int n;
int fa[N + 5], dep[N + 5], ptr[N + 5];

void addedge(int a, int b) {
    E[++ etot].to = b; E[etot].nxt = hd[a]; hd[a] = etot;
    E[++ etot].to = a; E[etot].nxt = hd[b]; hd[b] = etot;
}

void dfs(int u) {
    //for (int i;)

    thd[u][0] = dep[u];
    thd[u][1] = dep[u] - 1;
    ptr[u] = 1;
    if (fa[u]) {
        int f = fa[u];
        for (int i = 1; i <= ptr[f]; i ++) {
            ll g = gcd(val[u][1], val[f][i]);
            if (g == val[u][ptr[u]]) thd[u][ptr[u]] = thd[f][i];
            else val[u][++ ptr[u]] = g, thd[u][ptr[u]] = thd[f][i];
        }
    }

    for (int i = hd[u]; i; i = E[i].nxt) {
        int to = E[i].to;
        if (to == fa[u]) continue ;
        dep[to] = dep[u] + 1;
        fa[to] = u;
        dfs(to);
    }

    for (int i = 1; i <= ptr[u]; i ++)
        ans += val[u][i] * (thd[u][i - 1] - thd[u][i]);
}

int main() {

    scanf("%d", &n);
    for (int i = 1; i <= n; i ++)
        scanf("%I64d", &val[i][1]);
    for (int i = 1; i < n; i ++) {
        int a, b; scanf("%d%d", &a, &b);
        addedge(a, b);
    }

    dep[1] = 1, fa[1] = 0;

    dfs(1);

    printf("%I64d", ans % mod);

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>

const int N = 1e5;

using ll = long long;

const int mod = 1e9 + 7;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll val[N + 5][55], thd[N + 5][55], ans;

struct edge {
    int nxt, to;
} E[N << 1];
int hd[N + 5], etot;
int n;
int fa[N + 5], dep[N + 5], ptr[N + 5];

void addedge(int a, int b) {
    E[++ etot].to = b; E[etot].nxt = hd[a]; hd[a] = etot;
    E[++ etot].to = a; E[etot].nxt = hd[b]; hd[b] = etot;
}

void dfs(int u) {
    //for (int i;)

    thd[u][0] = dep[u];
    thd[u][1] = dep[u] - 1;
    ptr[u] = 1;
    if (fa[u]) {
        int f = fa[u];
        for (int i = 1; i <= ptr[f]; i ++) {
            ll g = gcd(val[u][1], val[f][i]);
            if (g == val[u][ptr[u]]) thd[u][ptr[u]] = thd[f][i];
            else val[u][++ ptr[u]] = g, thd[u][ptr[u]] = thd[f][i];
        }
    }

    for (int i = hd[u]; i; i = E[i].nxt) {
        int to = E[i].to;
        if (to == fa[u]) continue ;
        dep[to] = dep[u] + 1;
        fa[to] = u;
        dfs(to);
    }

    for (int i = 1; i <= ptr[u]; i ++)
        ans += val[u][i] * (thd[u][i - 1] - thd[u][i]) % mod, ans = ans % mod;
}

int main() {

    scanf("%d", &n);
    for (int i = 1; i <= n; i ++)
        scanf("%I64d", &val[i][1]);
    for (int i = 1; i < n; i ++) {
        int a, b; scanf("%d%d", &a, &b);
        addedge(a, b);
    }

    dep[1] = 1, fa[1] = 0;

    dfs(1);

    printf("%I64d", ans % mod);

    return 0;
}


//#pragma GCC optimize(3) //开启O3
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<cctype>
#include<set>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>

#define fi first
#define se second
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define root 1,n,1
#define PB push_back
#define MP make_pair
#define pi 3.1415926535898
#define MS(x,y) memset(x,y,sizeof(x))
#define lowbit(a)  (a&(-a))
#define S(x) (int)x.size()
#define L(x) (int)x.length()

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> P;
const int maxn = 1e6 + 10,modd = 1e9 + 7,SIZE = 100000,inf = 0x3f3f3f3f,INF = 0x7fffffff,hmod1=0x48E2DCE7,hmod2=0x60000005;
const int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
const double eps = 1e-8;

template <class T> inline void sc(T &x){char c;x=0;while((c=getchar())<'0');while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();}

inline LL min(LL a,LL b){return a < b ? a : b;}
inline LL max(LL a,LL b){return a > b ? a : b;}
inline LL gcd(LL a,LL b){ return b==0? a: gcd(b,a%b); }
inline LL exgcd(LL a,LL b,LL &x,LL &y){ LL d; (b==0? (x=1,y=0,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d; }
inline LL qpow(LL a,LL n){LL sum=1;while(n){if(n&1)sum=sum*a%modd;a=a*a%modd;n>>=1;}return sum;}
inline LL qmul(LL a,LL n){LL sum=0;while(n){if(n&1)sum=(sum+a)%modd;a=(a+a)%modd;n>>=1;}return sum;}
inline LL inv(LL a) {return qpow(a,modd-2);}
inline LL madd(LL a,LL b){return (a%modd+b%modd)%modd;}
inline LL mmul(LL a,LL b){return a%modd * b%modd;}
inline void uadd(LL &a,LL b){a = madd(a,b);}
inline void umul(LL &a,LL b){a = mmul(a,b);}
inline void umin(LL &a,LL b){a = min(a,b);}
inline void umax(LL &a,LL b){a = max(a,b);}
struct Edge{int to,next;}edge[2*maxn];
LL n,e,ans,head[maxn],w[maxn],f[maxn][30],g[maxn][30];
LL lg[maxn],depth[maxn];

void add_edge(int u,int v)
{
  edge[++e].to = v;
  edge[e].next = head[u];
  head[u] = e;
}

void dfs(int u,int fa)
{
  f[u][0] = fa;
  if(u != 1) g[u][0] = gcd(w[u],w[fa]);
  for(int i=1;(1<<i)<=depth[u];i++) f[u][i] = f[f[u][i-1]][i-1];
  for(int i=1;(1<<i)<=depth[u];i++) g[u][i] = gcd(g[u][i-1],g[f[u][i-1]][i-1]);
  for(int i=head[u];i;i=edge[i].next)
  {
    int v = edge[i].to;
    if(v == fa) continue;
    depth[v] = depth[u] + 1;
    dfs(v,u);
  }
}

void solve(int u,int fa)
{
  LL v = u,tmp = w[v];
  while(v != -1)
  {
    // cout << v << endl;
    LL d = depth[v];
    for(int i=lg[depth[v]];i>=0;i--)
    {
      if(g[v][i] != tmp)  continue;
      v = f[v][i];
    }
    uadd(ans,mmul(d-depth[v]+1,tmp));
    if(v <= 1)  break;
    v = f[v][0];
    tmp = gcd(tmp,w[v]);
  }
  for(int i=head[u];i;i=edge[i].next)
  {
    v = edge[i].to;
    if(v == fa) continue;
    solve(v,u);
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int a,b;
  cin >> n;
  lg[0] = -1;
  for(int i=1;i<=n;i++) lg[i] = lg[i>>1] + 1;
  for(int i=1;i<=n;i++) cin >> w[i];
  for(int i=0;i<n-1;i++)
  {
    cin >> a >> b;
    add_edge(a,b);
    add_edge(b,a);
  }
  dfs(1,-1);
  solve(1,-1);
  cout << ans << endl;
}
/*
32
402528994560 0 0 0 0 0 0 932646223872 893192888700 0 813583026900 0 0 0 0 143521875000 0 177570054144 186624000000 0 517655600000 202145625000 341007975000 0 116252718750 0 148561875000 0 304819200000 248474688000 0 103125000000
29 25
20 24
8 21
23 3
32 14
29 30
31 24
28 12
7 10
18 1
11 7
29 5
6 8
8 12
2 1
2 15
26 15
11 13
16 12
12 1
31 28
9 11
21 30
27 13
23 1
17 16
32 12
18 22
1 11
8 19
11 4
*/


//#pragma GCC optimize(3) //开启O3
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<cctype>
#include<set>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>

#define fi first
#define se second
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define root 1,n,1
#define PB push_back
#define MP make_pair
#define pi 3.1415926535898
#define MS(x,y) memset(x,y,sizeof(x))
#define lowbit(a)  (a&(-a))
#define S(x) (int)x.size()
#define L(x) (int)x.length()

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> P;
const int maxn = 1e6 + 10,modd = 1e9 + 7,SIZE = 100000,inf = 0x3f3f3f3f,INF = 0x7fffffff,hmod1=0x48E2DCE7,hmod2=0x60000005;
const int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
const double eps = 1e-8;

template <class T> inline void sc(T &x){char c;x=0;while((c=getchar())<'0');while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();}

inline LL min(LL a,LL b){return a < b ? a : b;}
inline LL max(LL a,LL b){return a > b ? a : b;}
inline LL gcd(LL a,LL b){ return b==0? a: gcd(b,a%b); }
inline LL exgcd(LL a,LL b,LL &x,LL &y){ LL d; (b==0? (x=1,y=0,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d; }
inline LL qpow(LL a,LL n){LL sum=1;while(n){if(n&1)sum=sum*a%modd;a=a*a%modd;n>>=1;}return sum;}
inline LL qmul(LL a,LL n){LL sum=0;while(n){if(n&1)sum=(sum+a)%modd;a=(a+a)%modd;n>>=1;}return sum;}
inline LL inv(LL a) {return qpow(a,modd-2);}
inline LL madd(LL a,LL b){return (a%modd+b%modd)%modd;}
inline LL mmul(LL a,LL b){return a%modd * b%modd;}
inline void uadd(LL &a,LL b){a = madd(a,b);}
inline void umul(LL &a,LL b){a = mmul(a,b);}
inline void umin(LL &a,LL b){a = min(a,b);}
inline void umax(LL &a,LL b){a = max(a,b);}
struct Edge{int to,next;}edge[2*maxn];
LL n,e,ans,head[maxn],w[maxn],f[maxn][30],g[maxn][30];
LL lg[maxn],depth[maxn];

void add_edge(int u,int v)
{
  edge[++e].to = v;
  edge[e].next = head[u];
  head[u] = e;
}

void dfs(int u,int fa)
{
  f[u][0] = fa;
  if(u != 1) g[u][0] = gcd(w[u],w[fa]);
  for(int i=1;(1<<i)<=depth[u];i++) f[u][i] = f[f[u][i-1]][i-1];
  for(int i=1;(1<<i)<=depth[u];i++) g[u][i] = gcd(g[u][i-1],g[f[u][i-1]][i-1]);
  for(int i=head[u];i;i=edge[i].next)
  {
    int v = edge[i].to;
    if(v == fa) continue;
    depth[v] = depth[u] + 1;
    dfs(v,u);
  }
}

void solve(int u,int fa)
{
  LL v = u,tmp = w[v];
  while(v != -1)
  {
    LL d = depth[v];
    for(int i=lg[depth[v]];i>=0;i--)
    {
      if(g[v][i] != tmp)  continue;
      v = f[v][i];
    }
    uadd(ans,mmul(d-depth[v]+1,tmp));
    if(v == 1)  break;
    v = f[v][0];
    tmp = gcd(tmp,w[v]);
  }
  for(int i=head[u];i;i=edge[i].next)
  {
    v = edge[i].to;
    if(v == fa) continue;
    solve(v,u);
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int a,b;
  cin >> n;
  lg[0] = -1;
  for(int i=1;i<=n;i++) lg[i] = lg[i>>1] + 1;
  for(int i=1;i<=n;i++) cin >> w[i];
  for(int i=0;i<n-1;i++)
  {
    cin >> a >> b;
    add_edge(a,b);
    add_edge(b,a);
  }
  dfs(1,-1);
  solve(1,-1);
  cout << ans << endl;
}
/*
5
4 5 6 0 8
1 2
1 3
1 4
4 5
*/


//#pragma GCC optimize(3) //开启O3
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<cctype>
#include<set>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>

#define fi first
#define se second
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define root 1,n,1
#define PB push_back
#define MP make_pair
#define pi 3.1415926535898
#define MS(x,y) memset(x,y,sizeof(x))
#define lowbit(a)  (a&(-a))
#define S(x) (int)x.size()
#define L(x) (int)x.length()

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> P;
const int maxn = 1e6 + 10,modd = 1e9 + 7,SIZE = 100000,inf = 0x3f3f3f3f,INF = 0x7fffffff,hmod1=0x48E2DCE7,hmod2=0x60000005;
const int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
const double eps = 1e-8;

template <class T> inline void sc(T &x){char c;x=0;while((c=getchar())<'0');while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();}

inline LL min(LL a,LL b){return a < b ? a : b;}
inline LL max(LL a,LL b){return a > b ? a : b;}
inline LL gcd(LL a,LL b){ return b==0? a: gcd(b,a%b); }
inline LL exgcd(LL a,LL b,LL &x,LL &y){ LL d; (b==0? (x=1,y=0,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d; }
inline LL qpow(LL a,LL n){LL sum=1;while(n){if(n&1)sum=sum*a%modd;a=a*a%modd;n>>=1;}return sum;}
inline LL qmul(LL a,LL n){LL sum=0;while(n){if(n&1)sum=(sum+a)%modd;a=(a+a)%modd;n>>=1;}return sum;}
inline LL inv(LL a) {return qpow(a,modd-2);}
inline LL madd(LL a,LL b){return (a%modd+b%modd)%modd;}
inline LL mmul(LL a,LL b){return a%modd * b%modd;}
inline void uadd(LL &a,LL b){a = madd(a,b);}
inline void umul(LL &a,LL b){a = mmul(a,b);}
inline void umin(LL &a,LL b){a = min(a,b);}
inline void umax(LL &a,LL b){a = max(a,b);}
struct Edge{int to,next;}edge[2*maxn];
LL n,e,ans,head[maxn],w[maxn],f[maxn][30],g[maxn][30];
LL lg[maxn],depth[maxn];

void add_edge(int u,int v)
{
  edge[++e].to = v;
  edge[e].next = head[u];
  head[u] = e;
}

void dfs(int u,int fa)
{
  f[u][0] = fa;
  if(u != 1) g[u][0] = gcd(w[u],w[fa]);
  for(int i=1;(1<<i)<=depth[u];i++) f[u][i] = f[f[u][i-1]][i-1];
  for(int i=1;(1<<i)<=depth[u];i++) g[u][i] = gcd(g[u][i-1],g[f[u][i-1]][i-1]);
  for(int i=head[u];i;i=edge[i].next)
  {
    int v = edge[i].to;
    if(v == fa) continue;
    depth[v] = depth[u] + 1;
    dfs(v,u);
  }
}

void solve(int u,int fa)
{
  LL v = u,tmp = w[v];
  while(v != -1)
  {
    // cout << v << endl;
    LL d = depth[v];
    for(int i=20;i>=0;i--)
    {
      if((1<<i) > depth[v]) continue;
      if(g[v][i] != tmp)  continue;
      v = f[v][i];
    }
    uadd(ans,mmul(d-depth[v]+1,tmp));
    if(v == 1)  break;
    v = f[v][0];
    tmp = gcd(tmp,w[v]);
  }
  for(int i=head[u];i;i=edge[i].next)
  {
    v = edge[i].to;
    if(v == fa) continue;
    solve(v,u);
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int a,b;
  cin >> n;
  lg[0] = -1;
  for(int i=1;i<=n;i++) lg[i] = lg[i>>1] + 1;
  for(int i=1;i<=n;i++) cin >> w[i];
  for(int i=0;i<n-1;i++)
  {
    cin >> a >> b;
    add_edge(a,b);
    add_edge(b,a);
  }
  dfs(1,-1);
  solve(1,-1);
  cout << ans << endl;
}
/*
32
402528994560 0 0 0 0 0 0 932646223872 893192888700 0 813583026900 0 0 0 0 143521875000 0 177570054144 186624000000 0 517655600000 202145625000 341007975000 0 116252718750 0 148561875000 0 304819200000 248474688000 0 103125000000
29 25
20 24
8 21
23 3
32 14
29 30
31 24
28 12
7 10
18 1
11 7
29 5
6 8
8 12
2 1
2 15
26 15
11 13
16 12
12 1
31 28
9 11
21 30
27 13
23 1
17 16
32 12
18 22
1 11
8 19
11 4
*/


//#pragma GCC optimize(3) //开启O3
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<cctype>
#include<set>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>

#define fi first
#define se second
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define root 1,n,1
#define PB push_back
#define MP make_pair
#define pi 3.1415926535898
#define MS(x,y) memset(x,y,sizeof(x))
#define lowbit(a)  (a&(-a))
#define S(x) (int)x.size()
#define L(x) (int)x.length()

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> P;
const int maxn = 1e6 + 10,modd = 1e9 + 7,SIZE = 100000,inf = 0x3f3f3f3f,INF = 0x7fffffff,hmod1=0x48E2DCE7,hmod2=0x60000005;
const int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
const double eps = 1e-8;

template <class T> inline void sc(T &x){char c;x=0;while((c=getchar())<'0');while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();}

inline LL min(LL a,LL b){return a < b ? a : b;}
inline LL max(LL a,LL b){return a > b ? a : b;}
inline LL gcd(LL a,LL b){ return b==0? a: gcd(b,a%b); }
inline LL exgcd(LL a,LL b,LL &x,LL &y){ LL d; (b==0? (x=1,y=0,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d; }
inline LL qpow(LL a,LL n){LL sum=1;while(n){if(n&1)sum=sum*a%modd;a=a*a%modd;n>>=1;}return sum;}
inline LL qmul(LL a,LL n){LL sum=0;while(n){if(n&1)sum=(sum+a)%modd;a=(a+a)%modd;n>>=1;}return sum;}
inline LL inv(LL a) {return qpow(a,modd-2);}
inline LL madd(LL a,LL b){return (a%modd+b%modd)%modd;}
inline LL mmul(LL a,LL b){return a%modd * b%modd;}
inline void uadd(LL &a,LL b){a = madd(a,b);}
inline void umul(LL &a,LL b){a = mmul(a,b);}
inline void umin(LL &a,LL b){a = min(a,b);}
inline void umax(LL &a,LL b){a = max(a,b);}
struct Edge{int to,next;}edge[2*maxn];
LL n,e,ans,head[maxn],w[maxn],f[maxn][30],g[maxn][30];
LL depth[maxn];

void add_edge(int u,int v)
{
  edge[++e].to = v;
  edge[e].next = head[u];
  head[u] = e;
}

void dfs(int u,int fa)
{
  f[u][0] = fa;
  if(u != 1) g[u][0] = gcd(w[u],w[fa]);
  for(int i=1;(1<<i)<=depth[u];i++) f[u][i] = f[f[u][i-1]][i-1];
  for(int i=1;(1<<i)<=depth[u];i++) g[u][i] = gcd(g[u][i-1],g[f[u][i-1]][i-1]);
  for(int i=head[u];i;i=edge[i].next)
  {
    int v = edge[i].to;
    if(v == fa) continue;
    depth[v] = depth[u] + 1;
    dfs(v,u);
  }
}

void solve(int u,int fa)
{
  LL v = u,tmp = w[v];
  while(v != -1)
  {
    // cout << v << endl;
    LL d = depth[v];
    for(int i=20;i>=0;i--)
    {
      if((1<<i) > depth[v]) continue;
      if(g[v][i] != tmp)  continue;
      v = f[v][i];
    }
    uadd(ans,mmul(d-depth[v]+1,tmp));
    if(v == 1)  break;
    v = f[v][0];
    tmp = gcd(tmp,w[v]);
  }
  for(int i=head[u];i;i=edge[i].next)
  {
    v = edge[i].to;
    if(v == fa) continue;
    solve(v,u);
  }
}

int main()
{
  int a,b;
  sc(n);
  for(int i=1;i<=n;i++) sc(w[i]);
  for(int i=0;i<n-1;i++)
  {
    sc(a),sc(b);
    add_edge(a,b);
    add_edge(b,a);
  }
  dfs(1,-1);
  solve(1,-1);
  printf("%I64d\n",ans);
}
/*
32
402528994560 0 0 0 0 0 0 932646223872 893192888700 0 813583026900 0 0 0 0 143521875000 0 177570054144 186624000000 0 517655600000 202145625000 341007975000 0 116252718750 0 148561875000 0 304819200000 248474688000 0 103125000000
29 25
20 24
8 21
23 3
32 14
29 30
31 24
28 12
7 10
18 1
11 7
29 5
6 8
8 12
2 1
2 15
26 15
11 13
16 12
12 1
31 28
9 11
21 30
27 13
23 1
17 16
32 12
18 22
1 11
8 19
11 4
*/


//#pragma GCC optimize(3) //开启O3
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<cctype>
#include<set>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>

#define fi first
#define se second
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define root 1,n,1
#define PB push_back
#define MP make_pair
#define pi 3.1415926535898
#define MS(x,y) memset(x,y,sizeof(x))
#define lowbit(a)  (a&(-a))
#define S(x) (int)x.size()
#define L(x) (int)x.length()

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> P;
const int maxn = 1e6 + 10,modd = 1e9 + 7,SIZE = 100000,inf = 0x3f3f3f3f,INF = 0x7fffffff,hmod1=0x48E2DCE7,hmod2=0x60000005;
const int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
const double eps = 1e-8;

template <class T> inline void sc(T &x){char c;x=0;while((c=getchar())<'0');while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();}

inline LL min(LL a,LL b){return a < b ? a : b;}
inline LL max(LL a,LL b){return a > b ? a : b;}
inline LL gcd(LL a,LL b){ return b==0? a: gcd(b,a%b); }
inline LL exgcd(LL a,LL b,LL &x,LL &y){ LL d; (b==0? (x=1,y=0,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d; }
inline LL qpow(LL a,LL n){LL sum=1;while(n){if(n&1)sum=sum*a%modd;a=a*a%modd;n>>=1;}return sum;}
inline LL qmul(LL a,LL n){LL sum=0;while(n){if(n&1)sum=(sum+a)%modd;a=(a+a)%modd;n>>=1;}return sum;}
inline LL inv(LL a) {return qpow(a,modd-2);}
inline LL madd(LL a,LL b){return (a%modd+b%modd)%modd;}
inline LL mmul(LL a,LL b){return a%modd * b%modd;}
inline void uadd(LL &a,LL b){a = madd(a,b);}
inline void umul(LL &a,LL b){a = mmul(a,b);}
inline void umin(LL &a,LL b){a = min(a,b);}
inline void umax(LL &a,LL b){a = max(a,b);}
struct Edge{int to,next;}edge[2*maxn];
LL n,e,ans,head[maxn],w[maxn],f[maxn][30],g[maxn][30];
LL depth[maxn];

void add_edge(int u,int v)
{
  edge[++e].to = v;
  edge[e].next = head[u];
  head[u] = e;
}

void dfs(int u,int fa)
{
  f[u][0] = fa;
  if(u != 1) g[u][0] = gcd(w[u],w[fa]);
  for(int i=1;(1<<i)<=depth[u];i++) f[u][i] = f[f[u][i-1]][i-1];
  for(int i=1;(1<<i)<=depth[u];i++) g[u][i] = gcd(g[u][i-1],g[f[u][i-1]][i-1]);
  for(int i=head[u];i;i=edge[i].next)
  {
    int v = edge[i].to;
    if(v == fa) continue;
    depth[v] = depth[u] + 1;
    dfs(v,u);
  }
}

void solve(int u,int fa)
{
  LL v = u,tmp = w[v];
  while(v != -1)
  {
    // cout << v << endl;
    LL d = depth[v];
    for(int i=20;i>=0;i--)
    {
      if((1<<i) > depth[v]) continue;
      if(gcd(g[v][i],tmp) != tmp)  continue;
      v = f[v][i];
    }
    uadd(ans,mmul(d-depth[v]+1,tmp));
    if(v == 1)  break;
    v = f[v][0];
    tmp = gcd(tmp,w[v]);
  }
  for(int i=head[u];i;i=edge[i].next)
  {
    v = edge[i].to;
    if(v == fa) continue;
    solve(v,u);
  }
}

int main()
{
  int a,b;
  sc(n);
  for(int i=1;i<=n;i++) sc(w[i]);
  for(int i=0;i<n-1;i++)
  {
    sc(a),sc(b);
    add_edge(a,b);
    add_edge(b,a);
  }
  dfs(1,-1);
  solve(1,-1);
  printf("%I64d\n",ans);
}
/*
32
402528994560 0 0 0 0 0 0 932646223872 893192888700 0 813583026900 0 0 0 0 143521875000 0 177570054144 186624000000 0 517655600000 202145625000 341007975000 0 116252718750 0 148561875000 0 304819200000 248474688000 0 103125000000
29 25
20 24
8 21
23 3
32 14
29 30
31 24
28 12
7 10
18 1
11 7
29 5
6 8
8 12
2 1
2 15
26 15
11 13
16 12
12 1
31 28
9 11
21 30
27 13
23 1
17 16
32 12
18 22
1 11
8 19
11 4
*/


//#pragma GCC optimize(3) //开启O3
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<cctype>
#include<set>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>

#define fi first
#define se second
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define root 1,n,1
#define PB push_back
#define MP make_pair
#define pi 3.1415926535898
#define MS(x,y) memset(x,y,sizeof(x))
#define lowbit(a)  (a&(-a))
#define S(x) (int)x.size()
#define L(x) (int)x.length()

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> P;
const int maxn = 1e6 + 10,modd = 1e9 + 7,SIZE = 100000,inf = 0x3f3f3f3f,INF = 0x7fffffff,hmod1=0x48E2DCE7,hmod2=0x60000005;
const int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
const double eps = 1e-8;

template <class T> inline void sc(T &x){char c;x=0;while((c=getchar())<'0');while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();}

inline LL min(LL a,LL b){return a < b ? a : b;}
inline LL max(LL a,LL b){return a > b ? a : b;}
inline LL gcd(LL a,LL b){ return b==0? a: gcd(b,a%b); }
inline LL exgcd(LL a,LL b,LL &x,LL &y){ LL d; (b==0? (x=1,y=0,d=a): (d=exgcd(b,a%b,y,x),y-=a/b*x)); return d; }
inline LL qpow(LL a,LL n){LL sum=1;while(n){if(n&1)sum=sum*a%modd;a=a*a%modd;n>>=1;}return sum;}
inline LL qmul(LL a,LL n){LL sum=0;while(n){if(n&1)sum=(sum+a)%modd;a=(a+a)%modd;n>>=1;}return sum;}
inline LL inv(LL a) {return qpow(a,modd-2);}
inline LL madd(LL a,LL b){return (a%modd+b%modd)%modd;}
inline LL mmul(LL a,LL b){return a%modd * b%modd;}
inline void uadd(LL &a,LL b){a = madd(a,b);}
inline void umul(LL &a,LL b){a = mmul(a,b);}
inline void umin(LL &a,LL b){a = min(a,b);}
inline void umax(LL &a,LL b){a = max(a,b);}
struct Edge{int to,next;}edge[2*maxn];
LL n,e,ans,head[maxn],w[maxn],f[maxn][30],g[maxn][30];
LL lg[maxn],depth[maxn];

void add_edge(int u,int v)
{
  edge[++e].to = v;
  edge[e].next = head[u];
  head[u] = e;
}

void dfs(int u,int fa)
{
  f[u][0] = fa;
  if(u != 1) g[u][0] = gcd(w[u],w[fa]);
  for(int i=1;(1<<i)<=depth[u];i++) f[u][i] = f[f[u][i-1]][i-1];
  for(int i=1;(1<<i)<=depth[u];i++) g[u][i] = gcd(g[u][i-1],g[f[u][i-1]][i-1]);
  for(int i=head[u];i;i=edge[i].next)
  {
    int v = edge[i].to;
    if(v == fa) continue;
    depth[v] = depth[u] + 1;
    dfs(v,u);
  }
}

void solve(int u,int fa)
{
  LL v = u,tmp = w[v];
  while(v != -1)
  {
    // cout << v << endl;
    LL d = depth[v];
    for(int i=20;i>=0;i--)
    {
      if((1<<i) > depth[v]) continue;
      if(g[v][i] != tmp)  continue;
      v = f[v][i];
    }
    uadd(ans,mmul(d-depth[v]+1,tmp));
    if(v == 1)  break;
    v = f[v][0];
    tmp = gcd(tmp,w[v]);
  }
  for(int i=head[u];i;i=edge[i].next)
  {
    v = edge[i].to;
    if(v == fa) continue;
    solve(v,u);
  }
}

int main()
{
  cout << gcd(0,124124);
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int a,b;
  cin >> n;
  lg[0] = -1;
  for(int i=1;i<=n;i++) lg[i] = lg[i>>1] + 1;
  for(int i=1;i<=n;i++) cin >> w[i];
  for(int i=0;i<n-1;i++)
  {
    cin >> a >> b;
    add_edge(a,b);
    add_edge(b,a);
  }
  dfs(1,-1);
  solve(1,-1);
  cout << ans << endl;
}
/*
32
402528994560 0 0 0 0 0 0 932646223872 893192888700 0 813583026900 0 0 0 0 143521875000 0 177570054144 186624000000 0 517655600000 202145625000 341007975000 0 116252718750 0 148561875000 0 304819200000 248474688000 0 103125000000
29 25
20 24
8 21
23 3
32 14
29 30
31 24
28 12
7 10
18 1
11 7
29 5
6 8
8 12
2 1
2 15
26 15
11 13
16 12
12 1
31 28
9 11
21 30
27 13
23 1
17 16
32 12
18 22
1 11
8 19
11 4
*/


#include <cstdio>
#include <vector>
#include <algorithm>

#define gcd(x,y) __gcd(x,y)

using namespace std;

const int MaxN = 1e5 + 5 ;
const long long Mod = 1e9 + 7;

long long a[MaxN];
vector<int> G[MaxN];
vector<long long> val[MaxN];
long long ans = 0LL;
bool vis[MaxN];

void dfs(int x){
	ans = (ans + a[x]) % Mod;
	int sz = G[x].size();
	for(int i = 0 ; i < sz ; i++){
		int to = G[x][i];
		if(vis[to])continue;
		int ssz = val[x].size();
		for(int j = 0 ; j < ssz ; j++){
			long long g = gcd(val[x][j],a[to]);
			ans = (ans + g) % Mod;
			val[to].push_back(g);
		}
		long long g = gcd(a[x],a[to]);
		ans = (ans + g) % Mod;
		val[to].push_back(g);
		dfs(to);
	}
}

int main(){
	int n ; scanf("%d",&n);
	for(int i = 1; i <= n ; i++)scanf("%lld",&a[i]);
	for(int i = 1 ; i < n ; i++){
		int u , v;
		scanf("%d %d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	vis[1] = true;
	dfs(1);
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<math.h>
#define ld long double
#define ll long long int
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define fi(a,b,c) for(int a=b;a<c;a++)
#define fd(a,b,c) for(int a=b;a>c;a--)
using namespace std;
int n,k;
char s[100009];
int main(){
   cin>>n>>k;
   cin>>s;
   ll sum=0;
   fi(i,0,n){
      sum+=s[i]-96;
   }
   if(k>n*26-sum & k>sum-n){
      cout<<-1;return 0;
   }
   int i=0;
   int t=0;
   if(k<=n*26-sum){
      while(k){
         t=min(k,122-s[i]);
         s[i]+=t;
         k-=(int)t;
         i++;
      }
   }else if(k<=sum-n){
      while(k){
         t=min(k,s[i]-97);
         s[i]-=t;
         k-=(int)t;
         i++;
      }
   }
   cout<<s;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<math.h>
#define ld long double
#define ll long long int
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define fi(a,b,c) for(int a=b;a<c;a++)
#define fd(a,b,c) for(int a=b;a>c;a--)
using namespace std;
int n,k;
char s[100009];
int main(){
   cin>>n>>k;
   cin>>s;
   ll sum=0;
   fi(i,0,n){
      sum+=s[i]-96;
   }
   if(k>n*26-sum & k>sum-n){
      cout<<-1;return 0;
   }
   int i=0;
   int t=0;
   if(k<=n*26-sum){
      while(k){
         t=min(k,122-s[i]);
         s[i]+=t;
         k-=(int)t;
         i++;
      }
   }else{
      while(k){
         t=min(k,s[i]-97);
         s[i]-=t;
         k-=(int)t;
         i++;
      }
   }
   cout<<s;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<math.h>
#define ld long double
#define ll long long int
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define fi(a,b,c) for(int a=b;a<c;a++)
#define fd(a,b,c) for(int a=b;a>c;a--)
using namespace std;
int n,k;
char s[100009];
int main(){
   cin>>n>>k;
   cin>>s;
   int sum=0;
   fi(i,0,n){
      sum+=s[i]-96;
   }
   if(k>n*26-sum & k>sum-n){
      cout<<-1;return 0;
   }
   int i=0;
   int t=0;
   while(k){
      if(s[i]>='n'){
         t=min(k,122-s[i]);
         s[i]+=t;
      }else{
         t=min(k,s[i]-'a');
         s[i]-=t;
      }
      k-=(int)t;
      i++;
   }
cout<<s;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
	ll n,p,i=0,x,m,s1=0,s2=0,y,z,c=0,k;
	string s,b;
	cin>>n>>k;
	cin>>s;
//	cout<<'z'-'b'<<" ";
	for(i=0;i<n;i++)
	{
		if(k>25)
		{
			if(abs(s[i]-'z')>abs(s[i]-'a'))
			{b[i]='z';
				k=k-('z'-s[i]);
			}
			else {
				b[i]='a';
			 	k=k-(s[i]-'a');
			}
		}
		else if(k!=0) {
			if(s[i]+k<='z')
			b[i]=s[i] + k;
			else b[i]=s[i] - k;
			k=0;
		}
		else b[i]=s[i];
	}
	if(k!=0)
	cout<<-1<<"\n";
	else{
		for(i=0;i<n;i++)
		cout<<b[i];
	}

	return 0;
}


  for (int i = 0; i < a.size(); ++i) {
    tot += (a[i] - b[i]);
  }

  return tot;
}

int main() {
  int n, k;
  cin >> n >> k;

  int k2 = k;
  string s;
  cin >> s;

  string ans;
  for (int i = 0; i < n; ++i) {
    if (k == 0) {
      ans.push_back(s[i]);
      continue;
    }

    int c = s[i] - 'a';
    int mx = 0;
    char x;
    int found = false;

    for (int j = c; j < 26; ++j) {
      int dist = j - c;
      if (dist <= k) {
        mx = max(dist, mx);
        x = j + 'a';
        found = true;
      }
    }

    if (found) {
      ans.push_back(x);
      k -= mx;
    }
  }

  if (k > 0) cout << -1;
  else {
    int tot = check(ans, s);
    if (tot != k2 || ans.size() != s.size()) assert(false);
    cout << ans;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() { IO
  int n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  string abc = "abcdefghijklmnopqrstuvwxyz";
  string ans = s;

  for (int i = 0; i < n && k > 0; ++i) {
    for (int j = 25; j >= 0; --j) {
      int diff = abs(abc[j] - s[i]);
      if (diff <= k) {
        ans[i] = abc[j];
        k -= diff;
        break;
      }
      else {
        while (j >= 0) {
          diff = abs(abc[j] - s[i]);
          if (diff == k) break;
          j --;
        }

        ans[i] = abc[j];
        k = 0;
        break;
      }
    }
  }

  if (k > 0) cout << -1;
  else cout << ans;

  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int check(string a, string b) {
  int tot = 0;
  for (int i = 0; i < a.size(); ++i) {
    tot += (a[i] - b[i]);
  }

  return tot;
}

int main() { IO
  int n, k;
  cin >> n >> k;

  int k2 = k;
  string s;
  cin >> s;

  vector< pair<int, int> > v(n);
  for (int i = 0; i < n; ++i) {
    v[i] = {'z' - s[i], i};
  }

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  string ans = s;
  for (int i = 0; i < n; ++i) {
    if (k == 0) break;

    int cur = v[i].first;
    int pos = v[i].second;

    int mx = -1;
    char x;
    for (int j = s[pos] - 'a', dist = 0; j < 26; ++j, dist ++) {
      if (dist <= k) {
        mx = max(mx, dist);
        x = j + 'a';
      }
    }

    if (mx != -1) {
      ans[pos] = x;
      k -= mx;
    }
  }

  if (ans.size() != n) assert(false);
  if (check(ans, s) == k2) {
    cout << ans;
  }
  else cout << -1;
  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int check(string a, string b) {
  int tot = 0;
  for (int i = 0; i < a.size(); ++i) {
    tot += (a[i] - b[i]);
  }

  return tot;
}

int main() {
  int n, k;
  cin >> n >> k;

  int k2 = k;
  string s;
  cin >> s;

  string ans;
  for (int i = 0; i < n; ++i) {
    if (k == 0) {
      ans.push_back(s[i]);
      continue;
    }

    int c = s[i] - 'a';
    int mx = 0;
    char x;
    int found = false;

    for (int j = c; j < 26; ++j) {
      int dist = j - c;
      if (dist <= k) {
        mx = max(dist, mx);
        x = j + 'a';
        found = true;
      }
    }

    if (found) {
      ans.push_back(x);
      k -= mx;
    }
  }

  if (k > 0) cout << -1;
  else {
    int tot = check(ans, s);
    if (tot != k2 || ans.size() != s.size()) assert(false);
    cout << ans;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() { IO
  int n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  string abc = "abcdefghijklmnopqrstuvwxyz";
  string ans = s;

  for (int i = 0; i < n && k > 0; ++i) {
    for (int j = 25; j >= 0; --j) {
      int diff = abc[j] - s[i];
      if (diff <= k) {
        ans[i] = abc[j];
        k -= diff;
        break;
      }
    }
  }

  if (n == 1000) cout << ans << endl;
  if (k > 0) cout << -1;
  else cout << ans;

  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() { IO
  int n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  string abc = "abcdefghijklmnopqrstuvwxyz";
  string ans = s;

  for (int i = 0; i < n && k > 0; ++i) {
    for (int j = 25; j >= 0; --j) {
      int diff = abs(abc[j] - s[i]);
      if (diff <= k) {
        ans[i] = abc[j];
        k -= diff;
        break;
      }
      else {
        while (j >= 0) {
          diff = abs(abc[j] - s[i]);
          if (diff == k) break;
          j --;
        }

        ans[i] = abc[j];
        k = 0;
        break;
      }
    }
  }

  if (n == 1000) cout << ans << endl;
  if (k > 0) cout << -1;
  else cout << ans;

  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int check(string a, string b) {
  int tot = 0;
  for (int i = 0; i < a.size(); ++i) {
    tot += (a[i] - b[i]);
  }

  return tot;
}

int main() { IO
  int n, k;
  cin >> n >> k;

  int k2 = k;
  string s;
  cin >> s;

  vector< pair<int, int> > v(n);
  for (int i = 0; i < n; ++i) {
    v[i] = {'z' - s[i], i};
  }

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  string ans = s;
  for (int i = 0; i < n; ++i) {
    if (k == 0) break;

    int cur = v[i].first;
    int pos = v[i].second;

    int mx = -1;
    char x;

    for (int j = s[pos] - 'a', dist = 0; j < 26; ++j, dist ++) {
      if (dist <= k) {
        mx = max(mx, dist);
        x = j + 'a';
      }
    }

    if (mx != -1) {
      ans[pos] = x;
      k -= mx;
    }
  }

  if (check(ans, s) == k2) {
    cout << ans;
  }
  else cout << -1;
  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() { IO
  int n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  string abc = "abcdefghijklmnopqrstuvwxyz";
  string ans = s;

  for (int i = 0; i < n && k > 0; ++i) {
    int mx = 0;
    char c;
    for (int j = 25; j >= 0; --j) {
      int diff = abs(abc[j] - s[i]);
      if (diff <= k && diff > mx) {
        mx = diff;
        c = abc[j];
      }
    }

    k -= mx;
    ans[i] = c;
  }

  if (k > 0) cout << -1;
  else cout << ans;

  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int check(string a, string b) {
  int tot = 0;
  for (int i = 0; i < a.size(); ++i) {
    tot += (a[i] - b[i]);
  }

  return tot;
}

int main() {
  int n, k;
  cin >> n >> k;

  int k2 = k;
  string s;
  cin >> s;

  string ans;
  for (int i = 0; i < n; ++i) {
    if (k == 0) {
      ans.push_back(s[i]);
      continue;
    }
    int c = s[i] - 'a';
    for (int j = 25; j >= 0; --j) {
      int dist = abs(c - j);
      if (dist <= k) {
        k -= dist;
        ans.push_back(char(j + 'a'));
        break;
      }
    }
  }

  if (k > 0) cout << -1;
  else {
    int tot = check(ans, s);
    if (tot != k2 || ans.size() != s.size()) assert(false);
    cout << ans;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() { IO
  int n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  string abc = "abcdefghijklmnopqrstuvwxyz";
  string ans = s;

  for (int i = 0; i < n && k > 0; ++i) {
    for (int j = 25; j >= 0; --j) {
      int diff = abc[j] - s[i];
      if (diff <= k) {
        ans[i] = abc[j];
        k -= diff;
        break;
      }
    }
  }

  if (k > 0) cout << -1;
  else cout << ans;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,k,len,i=0;
	char s[100005]={'\0'};
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	len=strlen(s);
	if(len*25<k)
	{
		printf("-1\n");
		return 0;
	}
	while(k>25)
	{
		if(s[i]!='a')
		{
			s[i]--;
		}
		else
		{
			s[i]='z';
		}
		i++;
		k-=25;
	}
	s[i]+=k;
	if(s[i]>'z')
	{
		s[i]-=26;
	}
	printf("%s\n",s);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,k,len,i=0;
	char s[100005]={'\0'};
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	len=strlen(s);
	if(len*25<k)
	{
		printf("-1\n");
		return 0;
	}
	while(k>=0)
	{
		k-='z'-s[i];
		s[i]='z';
		i++;
	}
	if(k<0)
	{
		s[i-1]+=k;
	}
	printf("%s\n",s);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,k,len,i=0;
	char s[100005]={'\0'};
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	len=strlen(s);
	if(len*25<k)
	{
		printf("-1\n");
		return 0;
	}
	while(k>=0)
	{
		k-='z'-s[i];
		s[i]='z';
		i++;
	}
	if(k<0)
	{
		s[i-1]+=k;
	}
	for(i=0;i<len;i++)
	{
		printf("%c",s[i]);
	}
	printf("\n");
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{  ll n,k;
cin>>n>>k;
char s[n],result[n];
scanf("%s",s);
if(25*n<k){
    printf("-1");
    return 0;
}ll m,l,q;
for(ll i=0;i<l;i++){
   m=s[i]-'a';
   l=25-m;
   if(m>l){
    q=min(m,k);
    result[i]=s[i]-q;
   k-=q;
   }
   else{
        q=min(l,k);
    result[i]=s[i]+q;
   k-=q;
   }
}
result[n]='\0';
puts(result);

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{  ll n,k;
cin>>n>>k;
char s[n],result[n];
scanf("%s",s);
if(25*n<k){
    printf("-1\n");
    return 0;
}ll m,l,q;
for(ll i=0;i<n;i++){
   m=s[i]-'a';
   l=25-m;
   if(m>l){
    q=min(m,k);
    result[i]=s[i]-q;
   k-=q;
   }
   else{
        q=min(l,k);
    result[i]=s[i]+q;
   k-=q;
   }
}
result[n]='\0';
puts(result);
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{  ll n,k;
cin>>n>>k;
char s[n],result[n];
scanf("%s",s);
ll m,l,q;
for(ll i=0;i<n;i++){
   m=s[i]-'a';
   l=25-m;
   if(m>l){
    q=min(m,k);
    result[i]=s[i]-q;
   k-=q;
   }
   else{
        q=min(l,k);
    result[i]=s[i]+q;
   k-=q;
   }
}
if(k>0)cout<<"-1"<<endl;
else{
result[n]='\0';
puts(result);
}
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{  ll n,k;
cin>>n>>k;
char s[n],result[n];
scanf("%s",s);
if(25*n<k){
    printf("-1");
    return 0;
}ll m,l,q;
for(ll i=0;i<l;i++){
   m=s[i]-'a';
   l=25-m;
   if(m>l){
    q=min(m,k);
    result[i]=s[i]-q;
   k-=q;
   }
   else{
        q=min(l,k);
    result[i]=s[i]+q;
   k-=q;
   }
}
for(int i=0;i<l;i++){
    printf("%c",result[i]);
}

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{  ll n,k;
cin>>n>>k;
char s[n],result[n];
scanf("%s",s);
if(25*n<k){
    printf("-1");
    return 0;
}
ll p=k/n;
ll q=p+(k%n);

for(ll i=0;i<n-1;i++){
    if(s[i]-p<97)result[i]=s[i]+p;
    else result[i]=s[i]-p;
}
 if(s[n-1]-q<97)result[n-1]=s[n-1]+q;
    else result[n-1]=s[n-1]-q;
result[n]='\0';
for(int i=0;i<n;i++)
    printf("%c",result[i]);

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{  ll n,k;
cin>>n>>k;
char s[n],result[n];
scanf("%s",s);
if(25*n<k){
    printf("-1");
    return 0;
}ll m,l,q;
for(ll i=0;i<l;i++){
   m=s[i]-'a';
   l=25-m;
   if(m>l){
    q=min(m,k);
    result[i]=s[i]-q;
   k-=q;
   }
   else{
        q=min(l,k);
    result[i]=s[i]+q;
   k-=q;
   }
}
for(int i=0;i<l;i++){
    printf("%c",result[i]);
}
printf("\n");

    return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;
int const N = 123456;
string s;
int n, k;

int dist(char a, char b)
{
	return abs(b - a);
}

int main()
{
	ios::sync_with_stdio(false);

	//cout << dist('e', 'c');
	//cout << dist('f', 'b');
	cin >> n >> k;
	cin >> s;
	//long long qwe = 0;
	//for (int i = 0; i < n; i++)
	//{
	//	qwe += dist(s[i], 'z');
	//}
	//if (k > qwe)
	//{
	//	cout << -1 << endl;
	//	return 0;
	//}
	for (int i = 0; i < n; i++)
	{
		if (k > 0)
		{
			if (dist(s[i], 'z') <= k)
			{
				k -= dist(s[i], 'z');
				s[i] = 'z';

			}
			else
			{
				s[i] += k;
				k = 0;
			}
		}
	}
	if (k > 0)
	{
		//cout << "-1" << endl;
		return 0;
	}
	cout << s << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;
int const N = 123456;
string s;
int n, k;

int dist(char a, char b)
{
	return abs(b - a);
}

int main()
{
	ios::sync_with_stdio(false);

	//cout << dist('e', 'c');
	//cout << dist('f', 'b');
	cin >> n >> k;
	cin >> s;
	long long qwe = 0;
	for (int i = 0; i < n; i++)
	{
		qwe += dist(s[i], 'z');
	}
	if (k > qwe)
	{
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		if (k > 0)
		{
			if (dist(s[i], 'z') <= k)
			{
				k -= dist(s[i], 'z');
				s[i] = 'z';

			}
			else
			{
				s[i] += k;
				k = 0;
			}
		}
	}
	if (k > 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	cout << s << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;
int const N = 123456;
string s;
int n, k;

int dist(char a, char b)
{
	return abs(b - a);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> k;
	cin >> s;

	for (int i = 0; i < n; i++)
	{
		if (k > 0)
		{
			if (dist(s[i], 'z') <= k)
			{
				k -= dist(s[i], 'z');
				s[i] = 'z';

			}
			else
			{
				s[i] += k;
				k = 0;
			}
		}
	}
	if (k > 0)
	{
		cout << -1 << endl;
		return 0;
	}
	cout << s << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int const N = 123456;
string s;
int n, k;

int dist(char a, char b)
{
	return abs(b - a);
}

int main()
{
	ios::sync_with_stdio(false);

	//cout << dist('e', 'c');
	//cout << dist('f', 'b');
	cin >> n >> k;
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		if (k > 0)
		{
			int d1 = dist(s[i], 'z');
			int d2 = dist(s[i], 'a');
			if (max(d1, d2) <= k)
			{
				k -= max(d1, d2);
				if (max(d1, d2) == d1)
				{
					s[i] = 'z';
				}
				else
				{
					s[i] = 'a';
				}
			}
			else
			{
				if (k <= d1)
				{
					s[i] += k;
				}
				else
				{
					s[i] -= k;
				}
				k = 0;
			}
		}
	}
	if (k > 0)
	{
		cout << -1 << endl;
		return 0;
	}
	cout << s << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>

using namespace std;
int const N = 123456;
string s;
int n, k;

int dist(char a, char b)
{
	return abs(b - a);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> k;
	cin >> s;

	for (int i = 0; i < n; i++)
	{
		if (k > 0)
		{
			if (dist(s[i], 'z') <= k)
			{
				k -= dist(s[i], 'z');
				s[i] = 'z';

			}
			else
			{
				s[i] += k;
				k = 0;
			}
		}
	}
	if (k > 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	cout << s << endl;
	return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345];
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
    {
        a1=s[i]-'a';
        a2='z'-s[i];
        if(a1<=k&&a2<=k)
        {
            if(a1>=a2)
            {
                s[i]='a';
                k-=a1;
            }
            else
            {
                s[i]='z';
                k-=a2;
            }
        }
        else
        {
            if(a1<k)
                s[i]=s[i]+k;
            else
                s[i]=s[i]-k;
            k=0;
        }
        if(k==0||(len-i)*26<k) break;
    }
    if(k) puts("-1");
    else printf("%s\n",s);
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    char s[12345];
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; i<len; i++)
        {
            a1=s[i]-'a';
            a2='z'-s[i];
            if(a1<=k&&a2<=k)
            {
                if(a1>=a2)
                {
                    s[i]='a';
                    k-=a1;
                }
                else
                {
                    s[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                    s[i]=s[i]+k;
                else
                    s[i]=s[i]-k;
                k=0;
            }
            if(k==0||(len-i)*26<k) break;
        }
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;

int d(char a,char b)
{
    return max(a-b,b-a);
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345],a[12345];
    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        for(i=0; i<len; i++)
        {
            a1=d('a',s[i]);
            a2=d('z',s[i]);
            if(max(a1,a2)<=k)
            {
                if(a1>=a2)
                {
                    a[i]='a';
                    k-=a1;
                }
                else
                {
                    a[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    a[i]=s[i]+k;
                }
                else
                {
                    a[i]=s[i]-k;
                }
                k=0;
            }
            if(k==0) break;
        }
        a[i+1]=0;
        if(k) puts("-1");
        else printf("%s%s\n",a,s+i+1);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    char s[12345];
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; i<len; i++)
        {
            sum=max('z'-s[i],s[i]-'a');
            if(sum<=k)
            {
                k-=sum;
                if('z'-s[i]>s[i]-'a') s[i]='z';
                else s[i]='a';
            }
            else
            {
                sum=s[i]+k;
                if(sum>'z') sum=s[i]-k;
                s[i]=sum;
            }
        }
        printf("%s\n",s);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;

int d(char a,char b)
{
    return max(a-b,b-a);
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345],a[12345];
    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        for(i=0; i<len; i++)
        {
            a1=d('a',s[i]);
            a2=d('z',s[i]);
            if(max(a1,a2)<=k)
            {
                if(a1>=a2)
                {
                    a[i]='a';
                    k-=a1;
                }
                else
                {
                    a[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    a[i]=s[i]+k;
                }
                else
                {
                    a[i]=s[i]-k;
                }
                k=0;
            }
        }
        a[len]=0;
        if(k) puts("-1");
        else printf("%s\n",a);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;

int d(char a,char b)
{
    return max(a-b,b-a);
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345],a[12345];
    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        for(i=0; i<len; i++)
        {
            a1=d('a',s[i]);
            a2=d('z',s[i]);
            if(max(a1,a2)<=k)
            {
                if(a1>=a2)
                {
                    a[i]='a';
                    k-=a1;
                }
                else
                {
                    a[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    a[i]=s[i]+k;
                }
                else
                {
                    a[i]=s[i]-k;
                }
                k=0;
            }
        }
        a[len]=0;
        if(k) puts("-1");
        else puts(a);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    char s[12345];
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; i<len; i++)
        {
            a1=s[i]-'a';
            a2='z'-s[i];
            if(a1<=k&&a2<=k)
            {
                if(a1>=a2)
                {
                    s[i]='a';
                    k-=a1;
                }
                else
                {
                    s[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                    s[i]=s[i]+k;
                else
                    s[i]=s[i]-k;
                k=0;
            }
            if(k==0) break;
        }
        printf("%s\n",s);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
char s[12345];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; i<len; i++)
        {
            //if(k==0) break;
            sum=max('z'-s[i],s[i]-'a');
            if(sum<=k)
            {
                k-=sum;
                if('z'-s[i]>s[i]-'a') s[i]='z';
                else s[i]='a';
            }
            else
            {
                sum=s[i]+k;
                if(sum>'z') sum=s[i]-k;
                s[i]=sum;
                k=0;
            }
            printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
char s[123456];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; i<len; i++)
        {
            //if(k==0) break;
            sum=max('z'-s[i],s[i]-'a');
            if(sum<=k)
            {
                k-=sum;
                if('z'-s[i]>s[i]-'a') s[i]='z';
                else s[i]='a';
            }
            else
            {
                sum=s[i]+k;
                if(sum>'z') sum=s[i]-k;
                s[i]=sum;
                k=0;
            }
            printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;

int d(char a,char b)
{
    return max(a-b,b-a);
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345],a[12345];
    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        for(i=0; i<len; i++)
        {
            a1=d('a',s[i]);
            a2=d('z',s[i]);
            if(max(a1,a2)<=k)
            {
                if(a1>=a2)
                {
                    a[i]='a';
                    k-=a1;
                }
                else
                {
                    a[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    a[i]=s[i]+k;
                }
                else
                {
                    a[i]=s[i]-k;
                }
                k=0;
            }
            if(k==0) break;
        }
        a[len]=0;
        if(k) puts("-1");
        else printf("%s\n",a);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345];
    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        for(i=0; i<len; i++)
        {
            a1=s[i]-'a';
            a2='z'-s[i];
            if(a1<=k&&a2<=k)
            {
                if(a1>=a2)
                {
                    s[i]='a';
                    k-=a1;
                }
                else
                {
                    s[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    s[i]=s[i]+k;
                }
                else
                {
                    s[i]=s[i]-k;
                }
                k=0;
            }
            if(k==0) break;
        }
        if(k) puts("-1");
        else printf("%s\n",s);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345];
    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        if(n*26<=k) {put("-1");continue;}
        for(i=0; i<len; i++)
        {
            a1=s[i]-'a';
            a2='z'-s[i];
            if(max(a1,a2)<=k)
            {
                if(a1>=a2)
                {
                    s[i]='a';
                    k-=a1;
                }
                else
                {
                    s[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    s[i]=s[i]+k;
                }
                else
                {
                    s[i]=s[i]-k;
                }
                k=0;
            }
            if(k==0) break;
        }
        if(k) puts("-1");
        else printf("%s\n",s);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345];
    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        for(i=0; i<len; i++)
        {
            a1=s[i]-'a';
            a2='z'-s[i];
            if(a1<=k&&a2<=k)
            {
                if(a1>=a2)
                {
                    s[i]='a';
                    k-=a1;
                }
                else
                {
                    s[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    s[i]=s[i]+k;
                }
                else
                {
                    s[i]=s[i]-k;
                }
                k=0;
            }
            if(k==0||(len-i)*26<k) break;
        }
        if(k) puts("-1");
        else printf("%s\n",s);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    char s[12345];
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; i<len; i++)
        {
            if(k==0) break;
            sum=max('z'-s[i],s[i]-'a');
            if(sum<=k)
            {
                k-=sum;
                if('z'-s[i]>s[i]-'a') s[i]='z';
                else s[i]='a';
            }
            else
            {
                sum=s[i]+k;
                if(sum>'z') sum=s[i]-k;
                s[i]=sum;
                k=0;
            }
        }
        printf("%s\n",s);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    char s[12345];
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; s[i]!=0; i++)
        {
            a1=s[i]-'a';
            a2='z'-s[i];
            if(a1<=k&&a2<=k)
            {
                if(a1>=a2)
                {
                    s[i]='a';
                    k-=a1;
                }
                else
                {
                    s[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                    s[i]=s[i]+k;
                else
                    s[i]=s[i]-k;
                k=0;
            }
            if(k==0) break;
        }
        printf("%s\n",s);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    char s[12345];
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; i<len; i++)
        {
            //if(k==0) break;
            sum=max('z'-s[i],s[i]-'a');
            if(sum<=k)
            {
                k-=sum;
                if('z'-s[i]>s[i]-'a') s[i]='z';
                else s[i]='a';
            }
            else
            {
                sum=s[i]+k;
                if(sum>'z') sum=s[i]-k;
                s[i]=sum;
                k=0;
            }
            printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;
    char s[12345];
    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        if(n*26<=k) {puts("-1");continue;}
        for(i=0; i<len; i++)
        {
            a1=s[i]-'a';
            a2='z'-s[i];
            if(max(a1,a2)<=k)
            {
                if(a1>=a2)
                {
                    s[i]='a';
                    k-=a1;
                }
                else
                {
                    s[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    s[i]=s[i]+k;
                }
                else
                {
                    s[i]=s[i]-k;
                }
                k=0;
            }
            if(k==0) break;
        }
        if(k) puts("-1");
        else printf("%s\n",s);
    }
    return 0;
}


/* ***********************************************
Author        :Maltub
Email         :xiang578@foxmail.com
Blog          :htttp://www.xiang578.top
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
char s[123456];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2;

    while(~scanf("%d%d",&n,&k))
    {
        scanf("%s",s);
        int len=strlen(s);
        for(i=0; i<len; i++)
        {
            a1=s[i]-'a';
            a2='z'-s[i];
            if(a1<=k&&a2<=k)
            {
                if(a1>=a2)
                {
                    s[i]='a';
                    k-=a1;
                }
                else
                {
                    s[i]='z';
                    k-=a2;
                }
            }
            else
            {
                if(a1<k)
                {
                    s[i]=s[i]+k;
                }
                else
                {
                    s[i]=s[i]-k;
                }
                k=0;
            }
            if(k==0) break;
        }
        if(k) puts("-1");
        else printf("%s\n",s);
    }
    return 0;
}
/*#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
char s[123456];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,j,n,k,a1,a2,sum=0;
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
        sum+=max(s[i]-'a','z'-s[i]);
    if(sum<k) printf("-1\n");
    else
    {
        for(i=0; i<len; i++)
        {
            //if(k==0) break;
            sum=max('z'-s[i],s[i]-'a');
            if(sum<=k)
            {
                k-=sum;
                if('z'-s[i]>s[i]-'a') s[i]='z';
                else s[i]='a';
            }
            else
            {
                sum=s[i]+k;
                if(sum>'z') sum=s[i]-k;
                s[i]=sum;
                k=0;
            }
            printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
}
*/