#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

const ll maxn =10e5+10;
const ld SADAT = 7.84e-17;
const ll INF = 1e9;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>bool checkmin(T &a,T b){return a > b ? a = b, 1 : 0;}
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}
struct edge{
    int t  , next;
    ll w;
}e[maxn];
int n, l , m , g[maxn];
vector<int> adj[maxn];
vector< pii > vec[maxn];
int timer;
vector<int> tin, tout;
vector<vector<int> > up;
bool inmst[maxn];
int par[maxn];
vector <int> comp[maxn];
int ans[maxn];
int depth[maxn] , son[maxn][20] , dad[maxn][20];
int cnt ;
struct yaint{
        int x , y, mark , k;
        ll w;
}yal[maxn];

bool cmp(yaint i , yaint j){
    return(i.w < j.w);
}

void dfs2(int v){
    for(int i=1;i<20;i++){
        dad[v][i]=dad[dad[v][i-1]][i-1];
        son[v][i]=max(son[dad[v][i-1]][i-1],son[v][i-1]);
    }
    for(int i=g[v];i;i=e[i].next){
        if(!depth[e[i].t]){
            depth[e[i].t]=depth[v]+1;
            dad[e[i].t][0]=v;
            son[e[i].t][0]=e[i].w;
            dfs2(e[i].t);
        }
    }
}

void add(int x,int y,int z){
    e[++cnt].t=y;
    e[cnt].w=z;
    e[cnt].next=g[x];
    g[x]=cnt;
}

int getpar(int v){
    if(par[v] == v){
        return(v);
    }
    par[v] = getpar(par[v]);
    return(par[v]);
}

void dfs(int v, int p){
    tin[v] = ++timer;
    //cout << v;
    up[v][0] = p;
    for (int i = 1; i <= l; ++i){
        up[v][i] = up[up[v][i-1]][i-1];
        //cout << l << '\t';
    }
    for (int i = 0 ; i < adj[v].size() ; i ++) {
        int u = adj[v][i];
        if(v == 3){
            //cout << u;
        }
        if (u!=p){
            dfs(u, v);
        }
    }
    //cout << v;
    tout[v] = ++timer;
    //cout << v;
}

bool is_ancestor(int u, int v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

bool cmp2(yaint i , yaint j){
    return(i.k < j . k );
}

int lca(int u, int v)
{
    if (is_ancestor(u, v))
        return u;
    if (is_ancestor(v, u))
        return v;
    for (int i = l; i >= 0; --i) {
        if (!is_ancestor(up[u][i], v))
            u = up[u][i];
    }
    return up[u][0];
}

void preprocess(int root) {
    tin.resize(n*2);
    tout.resize(n*2);
    timer = 0;
    l = ceil(log2(n));
    up.assign(n * 2, vector<int>(l + 1));
    dfs(root, root);

    //cout << 2;s
}

int pht(int x,int y){
    int h=depth[x]-depth[y],mx=0;
    for(int i = 0 ; h ; i ++){
        if(h & 1){
            mx=max(mx,son[x][i]);
            x=dad[x][i];
        }
        h>>=1;
    }
    return mx;
}

int main(){
    //migmig
    cin >> n >> m;
    for (int i = 1 ;i <= m; i ++){
        int x , y , w;
        cin >> x >> y >> w;
        vec[x].pb(make_pair(w , y));
        vec[y].pb(make_pair(w , x));
        yal[i].x = x , yal[i].y = y , yal[i].k = i , yal[i].w = w;
    }
    sort(yal + 1 , yal + m + 1, cmp);
    for (int i = 0 ; i < n ; i ++){
        par[i + 1] = i + 1;
    }
    for (int i = 1 ; i <= n ; i ++){
        if(getpar(yal[i].x) != getpar(yal[i].y)){
            yal[i].mark = 1;
            int x = yal[i].x , y = yal[i].y;
            adj[x].pb(y);
            //cout << 2;
            adj[y].pb(x);
            //cout << 2;
            par[par[yal[i].x]] = par[yal[i].y];
            add(yal[i].x , yal[i].y , yal[i].w);
            add(yal[i].y , yal[i].x , yal[i].w);
        }
    }
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        if(yal[i].mark){
            ans[getpar(yal[i].x)]+=yal[i].w;
        }
    }

    for (int i = 1 ; i <= n ; i ++){
        if(depth[i] == 0){
            son[i][0]  = 1e6;
            dad[i][0] = i;
            depth[i] = 1;
            dfs2(i);
        }
    }
    //cout << 2;
    sort(yal +1,yal + m + 1 , cmp2 );
    //cout << 2;
    preprocess(1);
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        int x = yal[i].x , y = yal[i] . y;
        int lc = lca(x , y);
        if(yal[i].mark){
            cout << ans[getpar(x)] << endl;
        }
        else{
            ll mx = max(pht(x , lc) , pht(y , lc));
            //cout << lc << endl;
            cout << (ll)ans[getpar(x)] - mx + yal[i].w << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

const ll maxn =10e5+10;
const ld SADAT = 7.84e-17;
const ll INF = 1e9;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>bool checkmin(T &a,T b){return a > b ? a = b, 1 : 0;}
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}
struct edge{
    int t  , next;
    ll w;
}e[maxn];
int n, l , m , g[maxn];
vector<int> adj[maxn];
int timer;
vector<int> tin, tout;
vector<vector<int> > up;
bool inmst[maxn];
int par[maxn];
ll ans[maxn];
int depth[maxn] , son[maxn][20] , dad[maxn][20];
int cnt ;
struct yall{
        int x , y, mark , k , w;
}yal[maxn];

bool cmp(yall i , yall j){
    return(i.w < j.w);
}

void dfs2(int v){
    for(int i=1;i<20;i++){
        dad[v][i]=dad[dad[v][i-1]][i-1];
        son[v][i]=max(son[dad[v][i-1]][i-1],son[v][i-1]);
    }
    for(int i=g[v];i;i=e[i].next){
        if(!depth[e[i].t]){
            depth[e[i].t]=depth[v]+1;
            dad[e[i].t][0]=v;
            son[e[i].t][0]=e[i].w;
            dfs2(e[i].t);
        }
    }
}

void add(int x,int y,int z){
    e[++cnt].t=y;
    e[cnt].w=z;
    e[cnt].next=g[x];
    g[x]=cnt;
}

int getpar(int v){
    if(par[v] == v){
        return(v);
    }
    par[v] = getpar(par[v]);
    return(par[v]);
}

void dfs(int v, int p){
    tin[v] = ++timer;
    //cout << v;
    up[v][0] = p;
    for (int i = 1; i <= l; ++i){
        up[v][i] = up[up[v][i-1]][i-1];
        //cout << l << '\t';
    }
    for (int i = 0 ; i < adj[v].size() ; i ++) {
        int u = adj[v][i];
        if(v == 3){
            //cout << u;
        }
        if (u!=p){
            dfs(u, v);
        }
    }
    //cout << v;
    tout[v] = ++timer;
    //cout << v;
}

bool is_ancestor(int u, int v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

bool cmp2(yall i , yall j){
    return(i.k < j . k );
}

int lca(int u, int v)
{
    if (is_ancestor(u, v))
        return u;
    if (is_ancestor(v, u))
        return v;
    for (int i = l; i >= 0; --i) {
        if (!is_ancestor(up[u][i], v))
            u = up[u][i];
    }
    return up[u][0];
}

void preprocess(int root) {
    tin.resize(n+100);
    tout.resize(n+100);
    timer = 0;
    l = ceil(log2(n));
    up.assign(n * 2, vector<int>(l + 1));
    dfs(root, root);

    //cout << 2;s
}

int pht(int x,int y){
    int h=depth[x]-depth[y],mx=0;
    for(int i = 0 ; h ; i ++){
        if(h & 1){
            mx=max(mx,son[x][i]);
            x=dad[x][i];
        }
        h>>=1;
    }
    return mx;
}

int main(){
    migmig
    cin >> n >> m;
    for (int i = 1 ;i <= m; i ++){
        int x , y , w;
        cin >> x >> y >> w;
        yal[i].x = x , yal[i].y = y , yal[i].k = i , yal[i].w = w;
    }
    sort(yal + 1 , yal + m + 1, cmp);
    for (int i =1 ; i <= n ; i ++){
        par[i ] = i ;
    }
    for (int i = 1 ; i <= m ; i ++){
        if(getpar(yal[i].x) != getpar(yal[i].y)){
            yal[i].mark = 1;
            int x = yal[i].x , y = yal[i].y;
            adj[x].pb(y);
            //cout << 2;
            adj[y].pb(x);
            //cout << 2;
            par[par[yal[i].x]] = par[yal[i].y];
            add(yal[i].x , yal[i].y , yal[i].w);
            add(yal[i].y , yal[i].x , yal[i].w);
        }
    }
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        if(yal[i].mark){
            ans[getpar(yal[i].x)]+=yal[i].w;
        }
    }

    for (int i = 1 ; i <= n ; i ++){
        if(depth[i] == 0){
            son[i][0]  = 1e6;
            dad[i][0] = i;
            depth[i] = 1;
            dfs2(i);
        }
    }
    //cout << 2;
    sort(yal +1,yal + m + 1 , cmp2 );
    //cout << 2;
    preprocess(1);
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        int x = yal[i].x , y = yal[i] . y;
        int lc = lca(x , y);
        if(yal[i].mark){
            cout << ans[getpar(x)] << endl;
        }
        else{
            ll mx = max(pht(x , lc) , pht(y , lc));
            //cout << lc << endl;
            cout << (ll)ans[getpar(x)] - mx + yal[i].w << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

const ll maxn =10e5+10;
const ld SADAT = 7.84e-17;
const ll INF = 1e9;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>bool checkmin(T &a,T b){return a > b ? a = b, 1 : 0;}
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}
struct edge{
    int t  , next;
    ll w;
}e[maxn];
int n, l , m , g[maxn];
vector<int> adj[maxn];
int timer;
vector<int> tin, tout;
vector<vector<int> > up;
bool inmst[maxn];
int par[maxn];
ll ans[maxn];
int depth[maxn] , son[maxn][20] , dad[maxn][20];
int cnt ;
struct yall{
        int x , y, mark , k , w;
}yal[maxn];

bool cmp(yall i , yall j){
    return(i.w < j.w);
}

void dfs2(int v){
    for(int i=1;i<20;i++){
        dad[v][i]=dad[dad[v][i-1]][i-1];
        son[v][i]=max(son[dad[v][i-1]][i-1],son[v][i-1]);
    }
    for(int i=g[v];i;i=e[i].next){
        if(!depth[e[i].t]){
            depth[e[i].t]=depth[v]+1;
            dad[e[i].t][0]=v;
            son[e[i].t][0]=e[i].w;
            dfs2(e[i].t);
        }
    }
}

void add(int x,int y,int z){
    e[++cnt].t=y;
    e[cnt].w=z;
    e[cnt].next=g[x];
    g[x]=cnt;
}

int getpar(int v){
    if(par[v] == v){
        return(v);
    }
    par[v] = getpar(par[v]);
    return(par[v]);
}

void dfs(int v, int p){
    tin[v] = ++timer;
    //cout << v;
    up[v][0] = p;
    for (int i = 1; i <= l; ++i){
        up[v][i] = up[up[v][i-1]][i-1];
        //cout << l << '\t';
    }
    for (int i = 0 ; i < adj[v].size() ; i ++) {
        int u = adj[v][i];
        if(v == 3){
            //cout << u;
        }
        if (u!=p){
            dfs(u, v);
        }
    }
    //cout << v;
    tout[v] = ++timer;
    //cout << v;
}

bool is_ancestor(int u, int v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

bool cmp2(yall i , yall j){
    return(i.k < j . k );
}

int lca(int u, int v)
{
    if (is_ancestor(u, v))
        return u;
    if (is_ancestor(v, u))
        return v;
    for (int i = l; i >= 0; --i) {
        if (!is_ancestor(up[u][i], v))
            u = up[u][i];
    }
    return up[u][0];
}

void preprocess(int root) {
    tin.resize(n);
    tout.resize(n);
    timer = 0;
    l = ceil(log2(n));
    up.assign(n * 2, vector<int>(l + 1));
    dfs(root, root);

    //cout << 2;s
}

int pht(int x,int y){
    int h=depth[x]-depth[y],mx=0;
    for(int i = 0 ; h ; i ++){
        if(h & 1){
            mx=max(mx,son[x][i]);
            x=dad[x][i];
        }
        h>>=1;
    }
    return mx;
}

int main(){
    migmig
    cin >> n >> m;
    for (int i = 1 ;i <= m; i ++){
        int x , y , w;
        cin >> x >> y >> w;
        yal[i].x = x , yal[i].y = y , yal[i].k = i , yal[i].w = w;
    }
    sort(yal + 1 , yal + m + 1, cmp);
    for (int i =1 ; i <= n ; i ++){
        par[i ] = i ;
    }
    for (int i = 1 ; i <= m ; i ++){
        if(getpar(yal[i].x) != getpar(yal[i].y)){
            yal[i].mark = 1;
            int x = yal[i].x , y = yal[i].y;
            adj[x].pb(y);
            //cout << 2;
            adj[y].pb(x);
            //cout << 2;
            par[par[yal[i].x]] = par[yal[i].y];
            add(yal[i].x , yal[i].y , yal[i].w);
            add(yal[i].y , yal[i].x , yal[i].w);
        }
    }
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        if(yal[i].mark){
            ans[getpar(yal[i].x)]+=yal[i].w;
        }
    }

    for (int i = 1 ; i <= n ; i ++){
        if(depth[i] == 0){
            son[i][0]  = 1e6;
            dad[i][0] = i;
            depth[i] = 1;
            dfs2(i);
        }
    }
    //cout << 2;
    sort(yal +1,yal + m + 1 , cmp2 );
    //cout << 2;
    preprocess(1);
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        int x = yal[i].x , y = yal[i] . y;
        int lc = lca(x , y);
        if(yal[i].mark){
            cout << ans[getpar(x)] << endl;
        }
        else{
            ll mx = max(pht(x , lc) , pht(y , lc));
            //cout << lc << endl;
            cout << (ll)ans[getpar(x)] - mx + yal[i].w << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

const ll maxn =10e5+10;
const ld SADAT = 7.84e-17;
const ll INF = 1e9;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>bool checkmin(T &a,T b){return a > b ? a = b, 1 : 0;}
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}
struct edge{
    int t , w , next;
}e[maxn];
int n, l , m , g[maxn];
vector<int> adj[maxn];
vector< pii > vec[maxn];
int timer;
vector<int> tin, tout;
vector<vector<int> > up;
bool inmst[maxn];
int par[maxn];
vector <int> comp[maxn];
int ans[maxn];
int depth[maxn] , son[maxn][20] , dad[maxn][20];
int cnt ;
struct yaint{
        int x , y , w , mark , k;
}yal[maxn];

bool cmp(yaint i , yaint j){
    return(i.w < j.w);
}

void dfs2(int v){
    for(int i=1;i<20;i++){
        dad[v][i]=dad[dad[v][i-1]][i-1];
        son[v][i]=max(son[dad[v][i-1]][i-1],son[v][i-1]);
    }
    for(int i=g[v];i;i=e[i].next){
        if(!depth[e[i].t]){
            depth[e[i].t]=depth[v]+1;
            dad[e[i].t][0]=v;
            son[e[i].t][0]=e[i].w;
            dfs2(e[i].t);
        }
    }
}

void add(int x,int y,int z){
    e[++cnt].t=y;
    e[cnt].w=z;
    e[cnt].next=g[x];
    g[x]=cnt;
}

int getpar(int v){
    if(par[v] == v){
        return(v);
    }
    par[v] = getpar(par[v]);
    return(par[v]);
}

void dfs(int v, int p){
    tin[v] = ++timer;
    //cout << v;
    up[v][0] = p;
    for (int i = 1; i <= l; ++i){
        up[v][i] = up[up[v][i-1]][i-1];
        //cout << l << '\t';
    }
    for (int i = 0 ; i < adj[v].size() ; i ++) {
        int u = adj[v][i];
        if(v == 3){
            //cout << u;
        }
        if (u!=p){
            dfs(u, v);
        }
    }
    //cout << v;
    tout[v] = ++timer;
    //cout << v;
}

bool is_ancestor(int u, int v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

bool cmp2(yaint i , yaint j){
    return(i.k < j . k );
}

int lca(int u, int v)
{
    if (is_ancestor(u, v))
        return u;
    if (is_ancestor(v, u))
        return v;
    for (int i = l; i >= 0; --i) {
        if (!is_ancestor(up[u][i], v))
            u = up[u][i];
    }
    return up[u][0];
}

void preprocess(int root) {
    tin.resize(n*2);
    tout.resize(n*2);
    timer = 0;
    l = ceil(log2(n));
    up.assign(n * 2, vector<int>(l + 1));
    dfs(root, root);

    //cout << 2;s
}

int pht(int x,int y){
    int h=depth[x]-depth[y],mx=0;
    for(int i = 0 ; h ; i ++){
        if(h & 1){
            mx=max(mx,son[x][i]);
            x=dad[x][i];
        }
        h>>=1;
    }
    return mx;
}

int main(){
    //migmig
    cin >> n >> m;
    for (int i = 1 ;i <= m; i ++){
        int x , y , w;
        cin >> x >> y >> w;
        vec[x].pb(make_pair(w , y));
        vec[y].pb(make_pair(w , x));
        yal[i].x = x , yal[i].y = y , yal[i].k = i , yal[i].w = w;
    }
    sort(yal + 1 , yal + m + 1, cmp);
    for (int i = 0 ; i < n ; i ++){
        par[i + 1] = i + 1;
    }
    for (int i = 1 ; i <= n ; i ++){
        if(getpar(yal[i].x) != getpar(yal[i].y)){
            yal[i].mark = 1;
            int x = yal[i].x , y = yal[i].y;
            adj[x].pb(y);
            //cout << 2;
            adj[y].pb(x);
            //cout << 2;
            par[par[yal[i].x]] = par[yal[i].y];
            add(yal[i].x , yal[i].y , yal[i].w);
            add(yal[i].y , yal[i].x , yal[i].w);
        }
    }
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        if(yal[i].mark){
            ans[getpar(yal[i].x)]+=yal[i].w;
        }
    }

    for (int i = 1 ; i <= n ; i ++){
        if(depth[i] == 0){
            son[i][0]  = 1e6;
            dad[i][0] = i;
            depth[i] = 1;
            dfs2(i);
        }
    }
    //cout << 2;
    sort(yal +1,yal + m + 1 , cmp2 );
    //cout << 2;
    preprocess(1);
    //cout << 2;
    for (int i = 1 ; i <= m ; i ++){
        int x = yal[i].x , y = yal[i] . y;
        int lc = lca(x , y);
        if(yal[i].mark){
            cout << ans[getpar(x)] << endl;
        }
        else{
            int mx = max(pht(x , lc) , pht(y , lc));
            //cout << lc << endl;
            cout << (ll)ans[getpar(x)] - mx + yal[i].w << endl;
        }
    }
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you wiint come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}
int cmp(const void *a, const void *b)
{
	return *((int*)a) - *((int*)b);
}

bool line[200000] = {false};
int m[450][26] = {0};

int main()
{
	//freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
	int k = 0, n = 0;
	int pos = 0, len = 0, total_len = 0;
	char ltr = 0;
	char token[256];

	scanf("%d", &k);
	scanf("%s", token);
	scanf("%d", &n);

	len = strlen(token);
	total_len = len * k;
	int part_len = sqrtf(total_len);
	int num_of_parts = total_len / part_len;
	if (total_len % part_len)
		num_of_parts++;

	for (int i = 0; i < k; i++)
		for (int j = 0; j < len; j++) {
			m[((i * len + j) / part_len)][token[j]-'a']++;
		}

	for (int t = 0; t < n; t++) {
		scanf("%d %c", &pos, &ltr);
		int count = 0;
		for (int i = 0; i < num_of_parts; i++) {
			count += m[i][ltr-'a'];
			if (count >= pos) {
				int begin = i * part_len;
				int skip = pos - (count - m[i][ltr-'a']);

				m[i][ltr-'a']--;

				for (int j = 0; begin % len + j < len; j++)
					if (token[begin%len+j] == ltr) {
						skip--;
						if (skip == 0) {
							line[begin + j] = true;
							goto OUT;
						}
					}
			}
		}
OUT:;
	}
	for (int i = 0; i < total_len; i++)
		if (!line[i])
			printf("%c", token[i%len]);
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
#include<ctime>
#include <complex>
#include <deque>
using namespace std;

bool cmp(long long  a,long long  b){
	if(a>b)
		return true;
	else return false;
}

#define sortS(a) sort(a.begin(),a.end())
#define sortN(a) sort(a.begin(),a.end(),cmp)

int wow[200000+10];
int n, k, p, MOD;
char c;
string str;

int main()
{
	//freopen("in.txt", "r", stdin );
    vector <int> data[150];
    cin >>k>> str;
    int size = str.length();
    for (int i = 0; i < size; i++)
        data[str[i]].push_back (i);
    cin>>n;
    for (int i=0 ; i<n ; i++){
        cin>>p>>c;
        MOD = data[c].size ();
		while (true) {
			if(  (wow[data[c][(p-1) % MOD] + (p-1)/MOD * size] == 1  ) == false)
				break;
			p++;
		}

        wow [data[c][ (p-1)%MOD] + (p-1)/MOD*size] = 1;
    }
    for (int i = 0; i < k; i++)
		for (int j = 0; j < size; j++)
			if ( wow[j + i*size]== false)
				cout<<str[j];
	cout<<endl;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
#include<ctime>
#include <complex>
#include <deque>
using namespace std;

bool cmp(int a,int b){
	if(a>b)
		return true;
	else return false;
}

#define sortS(a) sort(a.begin(),a.end())
#define sortN(a) sort(a.begin(),a.end(),cmp)

string str; //100
int k; //2000
int n; //20000
char wow[200000+2];
vector<int> oper[40];
int main(){
	//freopen("in.txt", "r", stdin );
	cin>>k;
	cin>>str;
	cin>>n;
	int sum[40]={false};
	int counter[40]={false};
	for(int i=0;i<n;i++){
		int p;
		char c;
		cin>>p>>c;
		sum[c-'a'] += p ;
		oper[c-'a'].push_back(sum[c-'a']);
	}

	for(int i=0;i<40;i++)
		sortN(oper[i]);

	for(int i=0;i<k;i++)
		for(int j=0;j<str.size();j++){
			if( oper[ str[j]-'a' ].size() > 0 && oper[ str[j]-'a' ][ oper[ str[j]-'a' ].size()-1 ] == counter[str[j]-'a'] +1 ){
				oper[ str[j]-'a' ].erase(  oper[ str[j]-'a' ].end()-1 );
				counter[str[j]-'a']++;
			}
			else{
				cout<<str[j];
				counter[str[j]-'a']++;
			}
		}
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
#include<ctime>
#include <complex>
#include <deque>
using namespace std;

bool cmp(long long  a,long long  b){
	if(a>b)
		return true;
	else return false;
}

#define sortS(a) sort(a.begin(),a.end())
#define sortN(a) sort(a.begin(),a.end(),cmp)

#define Max 200000
#define INF 1000000

char S[101];
int K, N, L;
int Ind[26][Max];
int P[26][Max];
int V[26];
int T = 0;

struct segment
{
	int l, r, lc, rc;
	char ch;
	int f[26], sum;
	segment() : sum(0), lc(-1), rc(-1), ch(-1){
		for (int i = 0; i < 26; i++) f[i] = 0;
	}
};
segment Tree[2 * Max];
void Build(int v, int l, int r)
{
	if (l < r)
	{
		Tree[v].l = l;
		Tree[v].r = r;
		T++;
		Tree[v].lc = T;
		Build(Tree[v].lc, l, (l + r) / 2);
		Tree[v].rc = T;
		Build(Tree[v].rc, (l + r) / 2 + 1, r);

		Tree[v].sum = Tree[Tree[v].lc].sum + Tree[Tree[v].rc].sum;
		for (int i = 0; i < 26; i++)
		{
			Tree[v].f[i] = Tree[Tree[v].lc].f[i] + Tree[Tree[v].rc].f[i];
		}
	}
	else
	{
		Tree[v].l = l;
		Tree[v].r = r;
		Tree[v].sum++;
		Tree[v].f[S[l % L] - 'a']++;
		Tree[v].ch = S[l % L];
		T++;
	}
}

void Print(int v)
{
	if (Tree[v].l < Tree[v].r)
	{
		if (Tree[Tree[v].lc].sum) Print(Tree[v].lc);
		if (Tree[Tree[v].rc].sum) Print(Tree[v].rc);
	}
	else
	{
		printf("%c", Tree[v].ch);
	}
}

void Remove(int v, int n, char c)
{
	Tree[v].sum--;
	Tree[v].f[c]--;
	if (Tree[v].l < Tree[v].r)
	{
		if (Tree[Tree[v].lc].f[c] < n)
		{
			Remove(Tree[v].rc, n - Tree[Tree[v].lc].f[c], c);
		}
		else
		{
			Remove(Tree[v].lc, n, c);
		}
	}
}

int main(){
	//freopen("in.txt", "r", stdin );
	cin>>K>>S;
	L = strlen(S);
	Build(0, 0, K*L-1);
	cin>>N;
	int a;
	char c;
	for (int i = 0; i < N; i++){
		cin>>a>>c;
		Remove(0, a, c - 'a');
	}
	Print(0);
	cout<<endl;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int n, k;
string s;

vector <vector <int>> a (26);

void main () {
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);

    cin >> k >> s >> n;
    int l = s.size();
    for (int i = 0; i < k; ++i)
        for (int j = 0; j < l; ++j)
            a[s[j] - 'a'].push_back(l*i + j + 1);
    for (int i = 0; i < n; ++i) {
        int p;
        char c;
        cin >> p >> c;
        a[c - 'a'].erase(a[c - 'a'].begin() + --p);
    }
    string ans;
    ans.resize (200000);
    int mx = 0;
    for (int i = 0; i < 26; ++i)
        for (int j = 0; j < a[i].size(); ++j) {
            ans[a[i][j] - 1] = i + 'a';
            mx = max (mx, a[i][j]);
        }
    ans.resize (mx);
    for (int i = 0; i < mx; ++i)
        if (!ans[i]) continue;
        else cout << ans[i];
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int n, k;
string s;

int cur[26];
vector <int> ins [26];

void main () {
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);

    cin >> k >> s >> n;
    int l = s.size();
    for (int i = 0; i < n; ++i) {
        int p;
        char c;
        cin >> p >> c;
        ins[c - 'a'].push_back (p);
    }
    for (int i = 0; i < k; ++i)
        for (int j = 0; j < l; ++j) {
            char t = s[j] - 'a';
            ++cur[t];
            if (!ins[t].empty() && cur[t] == ins[t].front()) {
                ins[t].erase (ins[t].begin());
                --cur[t];
            }
            else cout << s[j];
        }
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
using namespace std;

void main()
{
	long n,k,p,f,l,f1,s;
	char mas[110][2000],ch;
	map<char,int> m; m.clear();
	vector<map<char,int>> v; v.clear();
	scanf("%d",&k); scanf("%s",mas[0]); scanf("%d",&n);
	l=strlen(mas[0]);
	for(f=0;f<l;f++)
		m[mas[0][f]]++;
	v.push_back(m);
	for(f=1;f<k;f++)
	{
		v.push_back(m);
		for (f1=0;f1<l;f1++)
			mas[f][f1]=mas[0][f1];
	}
	while(n)
	{
		n--;
		scanf("%d %c",&p,&ch);
		f=0;
		s=0;
		while(s+(v[f])[ch]<p){f++;s+=(v[f])[ch];}
		for(f1=0;f1<l;f1++)
		{
			if(mas[f][f1]==ch)
			{
				s++;
				if(s==p)
				{
					mas[f][f1]='0';
					(v[f])[ch]--;
					break;
				}
			}
		}
	}
	for(f=0;f<k;f++)
		for(f1=0;f1<l;f1++)
			if(mas[f][f1]!='0')printf("%c",mas[f][f1]);
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
using namespace std;

void main()
{
	long n,k,p,f,l,f1,s;
	char mas[110][2000],ch;
	map<char,int> m; m.clear();
	vector<map<char,int>> v; v.clear();
	scanf("%d",&k); scanf("%s",mas[0]); scanf("%d",&n);
	l=strlen(mas[0]);
	for(f=0;f<l;f++)
		m[mas[0][f]]++;
	v.push_back(m);
	for(f=1;f<k;f++)
	{
		v.push_back(m);
		for (f1=0;f1<=l;f1++)
			mas[f][f1]=mas[0][f1];
	}
	while(n)
	{
		n--;
		scanf("%d %c",&p,&ch);
		f=0;
		s=0;
		while(s+(v[f])[ch]<p)
		{s+=(v[f])[ch];f++;}
		for(f1=0;f1<l;f1++)
		{
			if(mas[f][f1]==ch)
			{
				s++;
				if(s==p)
				{
					mas[f][f1]='0';
					(v[f])[ch]--;
					break;
				}
			}
		}
	}
	for(f=0;f<k;f++)
		for(f1=0;f1<l;f1++)
			if(mas[f][f1]!='0')printf("%c",mas[f][f1]);
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
using namespace std;

void main()
{
	long n,k,p,f,l,f1,s;
	char mas[2000][110],ch;
	map<char,int> m; m.clear();
	vector<map<char,int>> v; v.clear();
	scanf("%d",&k); scanf("%s",mas[0]); scanf("%d",&n);
	l=strlen(mas[0]);
	for(f=0;f<l;f++)
		m[mas[0][f]]++;
	v.push_back(m);
	for(f=1;f<k;f++)
	{
		v.push_back(m);
		for (f1=0;f1<=l;f1++)
			mas[f][f1]=mas[0][f1];
	}
	while(n)
	{
		n--;
		scanf("%d %c",&p,&ch);
		f=0;
		s=0;
		while(s+(v[f])[ch]<p)
		{s+=(v[f])[ch];f++;}
		for(f1=0;f1<l;f1++)
		{
			if(mas[f][f1]==ch)
			{
				s++;
				if(s==p)
				{
					mas[f][f1]='0';
					(v[f])[ch]--;
					break;
				}
			}
		}
	}
	for(f=0;f<k;f++)
		for(f1=0;f1<l;f1++)
			if(mas[f][f1]!='0')printf("%c",mas[f][f1]);
}


#include <iostream>
#include <stdio.h>
#include <Windows.h>

int main()
{
	int k,n;
	scanf("%d",&k);
	char str[101];
	char fullstr[500000];
	ZeroMemory(fullstr,sizeof(fullstr));
	scanf("%s",str);

	int len = strlen(str);
	for(int i = 0;i < k;i++)
	{
		memcpy(&fullstr[i*len],str,sizeof(char)*len);
	}

	scanf("%d",&n);

	int p;
	char ch;

	for(int i = 0;i < n;i++)
	{
		scanf("%d %c",&p,&ch);

		int c   = 0;
		int len = strlen(fullstr);
		for(int j = 0;j < len;j++)
		{
			if(fullstr[j] == ch)
			{
				c++;

				if(c == p)
				{
					memcpy(&fullstr[j],&fullstr[j+1],sizeof(char)*(len-1));
					fullstr[len-1] = 0;
					break;
				}
			}
		}
	}

	printf("%s\n",fullstr);

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <Windows.h>

int main()
{
	int k,n;
	scanf("%d",&k);
	char str[101];
	char fullstr[500000];
	ZeroMemory(fullstr,sizeof(fullstr));
	scanf("%s",str);

	int len = strlen(str);
	for(int i = 0;i < k;i++)
	{
		memcpy(&fullstr[i*len],str,sizeof(char)*len);
	}

	scanf("%d",&n);

	int p;
	char ch;
	len = strlen(fullstr);
	for(int i = 0;i < n;i++)
	{
		scanf("%d %c",&p,&ch);

		int c   = 0;

		for(int j = 0;j < len;j++)
		{
			if(fullstr[j] == ch)
			{
				c++;

				if(c == p)
				{
					fullstr[j] = 0;
					break;
				}
			}
		}
	}

	for(int i = 0;i < len;i++)
	{
		if(fullstr[i] == 0)continue;
		printf("%c",fullstr[i]);
	}

	printf("\n");

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <Windows.h>

int main()
{
	int k,n;
	scanf("%d",&k);
	char str[101];
	char fullstr[300000];
	ZeroMemory(fullstr,sizeof(fullstr));
	scanf("%s",str);

	int len = strlen(str);
	for(int i = 0;i < k;i++)
	{
		memcpy(&fullstr[i*len],str,sizeof(char)*len);
	}

	scanf("%d",&n);

	int p;
	char ch;

	for(int i = 0;i < n;i++)
	{
		scanf("%d %c",&p,&ch);

		int c   = 0;
		int len = strlen(fullstr);
		for(int j = 0;j < len;j++)
		{
			if(fullstr[j] == ch)
			{
				c++;

				if(c == p)
				{
					memcpy(&fullstr[j],&fullstr[j+1],sizeof(char)*(len-1));
					fullstr[len-1] = 0;
					break;
				}
			}
		}
	}

	printf("%s\n",fullstr);

	return 0;
}


#include <iostream>
#include <math.h>
#include <Windows.h>
#include <deque>

using namespace std;

struct Gist
{
	char str[105];
	int Freq[256];
};

int main()
{
	int k,n,p;
	char c;
	char str[105];
	int Freq[256];
	Gist* gist = 0;

	cin >> k;
	cin >> str;

	ZeroMemory(Freq,sizeof(Freq));

	int len = strlen(str);
	for(int i = 0;i < len;i++)
		Freq[str[i]]++;

	gist = new Gist[k];

	for(int i = 0;i < k;i++)
	{
		strcpy(gist[i].str,str);
		memcpy(gist[i].Freq,Freq,sizeof(int)*256);
	}

	cin >> n;

	for(int i = 0;i < n;i++)
	{
		cin >> p >> c;
		int pp = 0;

		do
		{
			p -= gist[pp++].Freq[c];
		}
		while(p > 0);

		pp--;
		int rem = p + gist[pp].Freq[c];

		int cnt = 0;

		len = strlen(gist[pp].str);
		for(int j = 0;j < len;j++)
		{
			if(gist[pp].str[j] == c)
			{
				cnt++;

				if(cnt == rem)
				{
					memmove(&gist[pp].str[j],&gist[pp].str[j+1],sizeof(char)*(len-1));
					gist[pp].str[len-1]=0;
		        	gist[pp].Freq[c]--;
			    	break;
				}
			}
		}
	}

	for(int i = 0;i < k;i++)cout << gist[i].str;

	return 0;
}


#include <iostream>
#include <string>
using namespace std;

int num[2001][300];
int pos[105][300];
bool struse[2001][105];
char str[105];

void process(char *str,int &k)
{
	int sz=strlen(str);
	for(int i=0;i<sz;i++)
	{
		num[0][str[i]]++;
		pos[num[0][str[i]]][str[i]]=i;
	}
	for(int i=1;i<k;i++)
		for(int j=0;j<300;j++)
			num[i][j]=num[0][j];
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n,k;
	scanf("%d",&k);
	scanf("%s",str);
	scanf("%d\n",&n);
	int p;char ch;
	process(str,k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %c\n",&p,&ch);
		int index=0;
		while(p>num[index][ch])p-=num[index][ch],index++;
		int tmp=p;
		while(struse[index][pos[tmp][ch]])tmp++;
		struse[index][pos[tmp][ch]]=1;
		for(int tt=tmp;tt<num[index][ch];tt++)pos[tt][ch]=pos[tt+1][ch];
		num[index][ch]--;
	}
	int sz=strlen(str);
	string ans;
	for(int i=0;i<k;i++)
		for(int j=0;j<sz;j++)if(!struse[i][j])ans+=str[j];
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

int num[2001][300];
int pos[105][300];
bool struse[2001][105];
char str[105];

void process(char *str,int &k)
{
	int sz=strlen(str);
	for(int i=0;i<sz;i++)
	{
		num[0][str[i]]++;
		pos[num[0][str[i]]][str[i]]=i;
	}
	for(int i=1;i<k;i++)
		for(int j=0;j<300;j++)
			num[i][j]=num[0][j];
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n,k;
	scanf("%d",&k);
	scanf("%s",str);
	scanf("%d\n",&n);
	int p;char ch;
	process(str,k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %c\n",&p,&ch);
		int index=0;
		while(p>num[index][ch])p-=num[index][ch],index++;
		int tmp=1,tt=0;
		//while(struse[index][pos[tmp][ch]])tmp++;
		for(;;tmp++)
		{
			if(!struse[index][pos[tmp][ch]])tt++;
			if(tt==p)break;
		}
		struse[index][pos[tmp][ch]]=1;
		num[index][ch]--;
	}
	int sz=strlen(str);
	string ans;
	for(int i=0;i<k;i++)
		for(int j=0;j<sz;j++)if(!struse[i][j])ans+=str[j];
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

int num[2001][300];
int pos[105][300];
bool struse[2001][105];
char str[105];

void process(char *str,int &k)
{
	int sz=strlen(str);
	for(int i=0;i<sz;i++)
	{
		num[0][str[i]]++;
		pos[num[0][str[i]]][str[i]]=i;
	}
	for(int i=1;i<k;i++)
		for(int j=0;j<300;j++)
			num[i][j]=num[0][j];
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n,k;
	scanf("%d",&k);
	scanf("%s",str);
	scanf("%d\n",&n);
	int p;char ch;
	process(str,k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %c\n",&p,&ch);
		int index=0;
		while(p>num[index][ch])p-=num[index][ch],index++;
		int tmp=p;
		while(struse[index][pos[tmp][ch]])tmp++;
		struse[index][pos[tmp][ch]]=1;
		num[index][ch]--;
	}
	int sz=strlen(str);
	string ans;
	for(int i=0;i<k;i++)
		for(int j=0;j<sz;j++)if(!struse[i][j])ans+=str[j];
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main()
{
	int l,k,n,p,pos;
	char c,s[101],as[200010]={0};
	scanf("%d%s%d",&k,s,&n);
	l=strlen(s);
	while(k--)
	{
		strcat(as,s);
		l+=l;
	}
	while(n--)
	{
		pos=-1;
		cin>>p>>c;
		while(p--)
			while(1)
			{
				pos++;
				if(as[pos]==c)
					break;
			}
		as[pos]=0;
	}
	for(pos=0;pos<l;pos++)
		if(as[pos])
			printf("%c",as[pos]);
	printf("\n");
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
struct Node
{
	string s;
	int cnt[26];
};
Node Str[2000];
int main()
{
	int i,k,n,p,pos,cn;
	char c;
	string s;
	cin>>k>>s>>n;
	Str[0].s=s;
	for(i=0;i<26;i++)
		Str[0].cnt[i]=0;
	i=s.length();
	while(i--)
		Str[0].cnt[s.at(i)-'a']++;
	for(i=1;i<k;i++)
		Str[i]=Str[0];
	while(n--)
	{
		pos=i=-1;
		cin>>p>>c;
		cn=c-'a';
		while(p>0)
		{
			i++;
			p=p-Str[i].cnt[cn];
		}
		p=p+Str[i].cnt[cn];
		Str[i].cnt[cn]--;
		while(p--)
			pos=Str[i].s.find(c,pos+1);
		Str[i].s.erase(pos,1);
	}
	for(i=0;i<k;i++)
			cout<<Str[i].s;
	cout<<endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int k,n,p,pos;
	string s;
	char c;
	cin>>k>>s>>n;
	while(--k)
		s+=s;
	while(n--)
	{
		pos=-1;
		cin>>p>>c;
		while(p--)
			pos=s.find(c,pos+1);
		s.erase(pos,1);
	}
	cout<<s<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>
#include <set>
#include <stack>
#include <list>
#include <string>
using namespace std;

#pragma comment(linker, "/STACK:64000000")

#define tm TMM

struct quer {
    int pos;
    char sym;
    int ind;
};

const int inf = 1e9;

int k, n;
string s;
quer q[20005];
bool used[30][200005];
int cnt[30];
int tm[1000005];

inline bool cmpq(const quer & L, const quer & R)
{
    if (L.sym == R.sym)
        return L.ind < R.ind;
    return L.sym < R.sym;
}
void init()
{
    for (int i = 0; i < 1000005; i++)
        tm[i] = inf;
}
void create_tree_mn(int l, int r, int id)
{
    if (l > r) return;
    if (l == r) {
        tm[id] = l;
        return;
    }
    int mid = (l + r)/2;
    create_tree_mn(l, mid, id*2);
    create_tree_mn(mid + 1, r, id*2 + 1);
    tm[id] = min(tm[id*2], tm[id*2 + 1]);
}
void update_tree_mn(int l, int r, int id, int num)
{
    if (l > r) return;
    if (l == r) {
        tm[id] = inf;
        return;
    }
    int mid = (l + r)/2;
    if (num >= l && num <= mid)
        update_tree_mn(l, mid, id*2, num);
    if (num >= mid + 1 && num <= r)
        update_tree_mn(mid + 1, r, id*2 + 1, num);
    tm[id] = min(tm[id*2], tm[id*2 + 1]);
}
int get_min(int l, int r, int id, int tl, int tr)
{
    if (l > r) return inf;
    if (l >= tl && r <= tr) return tm[id];
    int mid = (l + r)/2;
    int mn[2]; mn[0] = mn[1] = inf;
    if (tl >= l && tl <= mid)
        mn[0] = get_min(l, mid, id*2, tl, min(tr, mid));
    if (tr >= mid + 1 && tr <= r)
        mn[1] = get_min(mid + 1, r, id*2 + 1, max(tl, mid + 1), tr);
    return min(mn[0], mn[1]);
}
int main()
{
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    cin >> k;
    cin >> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int pos; char sym;
        cin >> pos >> sym;
        q[i].pos = pos;
        q[i].sym = sym;
        q[i].ind = i;
    }

    char sym = ('a' - 1);
    sort(q, q + n, &cmpq);

    for (int i = 0; i < n; i++) {
        if (sym != q[i].sym) {
            sym = q[i].sym;
            init();
            create_tree_mn(1, 200000, 1);
        }
        int l = 1;
        int r = q[i].pos;
        r = get_min(1, 200000, 1, r, 200000);
        used[q[i].sym - 'a' + 1][r] = true;
        update_tree_mn(1, 200000, 1, r);
        int j = i + 1;
        while (q[j].sym == q[i].sym) {
            if (q[j].pos >= q[i].pos)
                q[j].pos++;
            j++;
        }
    }

    for (int i = 0; i < k; i++) {
        for (int j = 0; j < s.size(); j++) {
            cnt[s[j]]++;
            if (!used[s[j] - 'a' + 1][cnt[s[j]]])
                putchar(s[j]);
        }
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>
#include <set>
#include <stack>
#include <list>
#include <string>
using namespace std;

#pragma comment(linker, "/STACK:64000000")

struct quer {
    int pos;
    char sym;
    int ind;
};

const int inf = 1e9;

int k, n;
string s;
quer q[20005];
bool used[30][200005];
int cnt[30];
int ts[1500005];

inline bool cmpq(const quer & L, const quer & R)
{
    if (L.sym == R.sym)
        return L.ind < R.ind;
    return L.sym < R.sym;
}
void init()
{
    for (int i = 0; i < 1500005; i++)
        ts[i] = 0;
}
void create_tree(int l, int r, int id)
{
    if (l > r) return;
    if (l == r) {
        ts[id] = 1;
        return;
    }
    int mid = (l + r)/2;
    create_tree(l, mid, id*2);
    create_tree(mid + 1, r, id*2 + 1);
    ts[id] = ts[id*2] + ts[id*2 + 1];
}
void update_tree(int l, int r, int id, int num)
{
    if (l > r) return;
    if (l == r) {
        ts[id] = 0;
        return;
    }
    int mid = (l + r)/2;
    if (num >= l && num <= mid)
        update_tree(l, mid, id*2, num);
    if (num >= mid + 1 && num <= r)
        update_tree(mid + 1, r, id*2 + 1, num);
    ts[id] = ts[id*2] + ts[id*2 + 1];
}
int find_tree(int l, int r, int id, int val)
{
    if (l > r) return 0;
    if (l == r) {
        return l;
    }
    int mid = (l + r)/2;
    if (ts[id*2] >= val)
        return find_tree(l, mid, id*2, val);
    else
        return find_tree(mid + 1, r, id*2 + 1, val - ts[id*2]);
}
int main()
{
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    cin >> k;
    cin >> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int pos; char sym;
        cin >> pos >> sym;
        q[i].pos = pos;
        q[i].sym = sym;
        q[i].ind = i;
    }

    char sym = ('a' - 1);
    sort(q, q + n, &cmpq);

    for (int i = 0; i < n; i++) {
        if (sym != q[i].sym) {
            sym = q[i].sym;
            init();
            create_tree(1, 200000, 1);
        }
        int l = 1;
        int r = q[i].pos;
        r = find_tree(1, 200000, 1, r);
        used[q[i].sym - 'a' + 1][r] = true;
        update_tree(1, 200000, 1, r);
    }

    for (int i = 0; i < k; i++) {
        for (int j = 0; j < s.size(); j++) {
            cnt[s[j] - 'a' + 1]++;
            if (!used[s[j] - 'a' + 1][cnt[s[j] - 'a' + 1]])   {
                putchar(s[j]);
            }
        }
    }

    cout << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>
#include <set>
#include <stack>
#include <list>
#include <string>
using namespace std;

#pragma comment(linker, "/STACK:64000000")

struct quer {
    int pos;
    char sym;
    int ind;
};

const int inf = 1e9;

int k, n;
string s;
quer q[20005];
bool used[30][200005];
int cnt[30];
int ts[1500005];

inline bool cmpq(const quer & L, const quer & R)
{
    if (L.sym == R.sym)
        return L.ind < R.ind;
    return L.sym < R.sym;
}
void init()
{
    for (int i = 0; i < 1500005; i++)
        ts[i] = 0;
}
void create_tree(int l, int r, int id)
{
    if (l > r) return;
    if (l == r) {
        ts[id] = 1;
        return;
    }
    int mid = (l + r)/2;
    create_tree(l, mid, id*2);
    create_tree(mid + 1, r, id*2 + 1);
    ts[id] = ts[id*2] + ts[id*2 + 1];
}
void update_tree(int l, int r, int id, int num)
{
    if (l > r) return;
    if (l == r) {
        ts[id] = 0;
        return;
    }
    int mid = (l + r)/2;
    if (num >= l && num <= mid)
        update_tree(l, mid, id*2, num);
    if (num >= mid + 1 && num <= r)
        update_tree(mid + 1, r, id*2 + 1, num);
    ts[id] = ts[id*2] + ts[id*2 + 1];
}
int find_tree(int l, int r, int id, int val)
{
    if (l > r) return 0;
    if (l == r) {
        return l;
    }
    int mid = (l + r)/2;
    if (ts[id*2] >= val)
        return find_tree(l, mid, id*2, val);
    else
        return find_tree(mid + 1, r, id*2 + 1, val - ts[id*2]);
}
int main()
{
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    cin >> k;
    cin >> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int pos; char sym;
        cin >> pos >> sym;
        q[i].pos = pos;
        q[i].sym = sym;
        q[i].ind = i;
    }

    char sym = ('a' - 1);
    sort(q, q + n, &cmpq);

    for (int i = 0; i < n; i++) {
        if (sym != q[i].sym) {
            sym = q[i].sym;
            init();
            create_tree(1, 200000, 1);
        }
        int l = 1;
        int r = q[i].pos;
        r = find_tree(1, 200000, 1, r);
        used[q[i].sym - 'a' + 1][r] = true;
        update_tree(1, 200000, 1, r);
    }

    for (int i = 0; i < k; i++) {
        for (int j = 0; j < s.size(); j++) {
            cnt[s[j]]++;
            if (!used[s[j] - 'a' + 1][cnt[s[j]]])   {
                putchar(s[j]);
            }
        }
    }

    cout << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>

#pragma comment(linker,"/STACK:640000000")

using namespace std;

vector <int> in[250];
vector <int> next[250];

int k , use[250];
string s , t ;

int main()
{
  //("input.txt","r",stdin);
  //("output.txt","w",stdout);
  cin >> k >> s;
  for (int i = 1 ; i <= k ; i ++ )
      t += s;
  for (int i = 0 ; i < t.size() ; i ++ )
      in[t[i]].push_back(i),
      next[t[i]].push_back(next[t[i]].size() );
  int n , val ;
  char c;
  scanf("%d",&n);
  for (int i = 1 ; i <= n ; i ++ ) {
    scanf("%d%c%c",&val,&c,&c);
    val -- ;
    int j = val ;
    while ( in[c][j] == -1 )
        j = next[c][j];
    t[in[c][j]] = 0;
    in[c][j] = -1;
    next[c][val] = j + 1;
  };
  for (int i = 0 ; i < t.size() ; i ++ )
      if ( t[i] )
          printf("%c",t[i]);
  cout << endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>

#pragma comment(linker,"/STACK:640000000")

using namespace std;

string s[2001];

int block[2001][301] , k , n , val ;
char c;

int main()
{
  //("input.txt","r",stdin);
  //("output.txt","w",stdout);
  cin >> k >> s[1];
  for (int i = 2 ; i <= k ; i ++ )
      s[i] = s[1];
  for (int i = 0 ; i < s[1].size() ; i ++ )
      for (int j = 1 ; j <= k ; j ++ )
          block[j][s[1][i]] ++ ;
  scanf("%d",&n);
  for (int i = 1 ; i <= n ; i ++ ) {
      scanf("%d%c%c",&val,&c,&c);
      int j = 1;
      while ( val - block[j][c] > 0 ) {
            val -= block[j][c];
            j ++ ;
      };
      for (int k = 0 ; k < s[1].size() ; k ++ ) {
          if ( s[j][k] == c && val == 1 ) {
            s[j][k] = 0;
            block[j][c] -- ;
            break;
          };
          if ( s[j][k] == c )
              val -- ;
      };
  };
  for (int i = 1 ; i <= k ; i ++ )
      for (int j = 0 ; j < s[1].size() ; j ++ )
          if ( s[i][j] )
                cout << s[i][j];
  cout << endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>

#pragma comment(linker,"/STACK:640000000")

using namespace std;

string s[2001];

int block[2001][301] , k , n , val ;
char c;

int main()
{
  //("input.txt","r",stdin);
  //("output.txt","w",stdout);
  cin >> k >> s[1];
  for (int i = 2 ; i <= k ; i ++ )
	  s[i] = s[1];
  for (int i = 0 ; i < s[1].size() ; i ++ )
	  for (int j = 1 ; j <= k ; j ++ )
		  block[j][s[1][i]] ++ ;
  scanf("%d",&n);
  for (int i = 1 ; i <= n ; i ++ ) {
	  scanf("%d%c%c",&val,&c,&c);
	  int j = 1;
	  while ( val - block[j][c] > 0 ) {
			val -= block[j][c];
			j ++ ;
	  };
	  for (int k = 0 ; k < s[1].size() ; k ++ ) {
		  if ( s[j][k] == c && val == 1 ) {
			s[j][k] = 0;
			break;
		  };
		  if ( s[j][k] == c )
			  val -- ;
	  };
  };
  for (int i = 1 ; i <= k ; i ++ )
	  for (int j = 0 ; j < s[1].size() ; j ++ )
		  if ( s[i][j] )
				cout << s[i][j];
  cout << endl;
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define x first
#define y second
VI a[26], q[26];
char s[2222];
int n, k, m;
int main() {
	scanf("%d", &k);
	scanf("%s", s);
	n = (int)strlen(s);
	for(int j = 0; j < n; ++j)
		for(int i = 0; i < k; ++i)
			a[s[j] - 'a'].pb(j + n * i);
	scanf("%d", &m);
	for(int i = 0; i < m; ++i) {
		char who; int pos;
		scanf("%d %c", &pos, &who);
		--pos;
		q[who - 'a'].pb(pos);
	}
	vector<pair<int, char> > ans(0);
	for(int let = 0; let < 26; ++let) {
		for(int i = 0; i < L(q[let]); ++i) {
			for(int j = 0; j < i; ++j)
				if (q[let][j] <= q[let][i]) q[let][i]++;
			int pos = i; while(pos && q[let][pos] < q[let][pos - 1]) { swap(q[let][pos], q[let][pos - 1]); --pos; }
		}
		int pos = 0;
		for(int i = 0; i < L(a[let]); ++i) {
			while(pos < L(q[let]) && q[let][pos] < i) ++pos;
			if (pos < L(q[let]) && q[let][pos] == i) continue;
			else ans.pb(mp(a[let][i], 'a' + let));
		}
	}
	sort(all(ans));
	for(int i = 0; i < L(ans); ++i) printf("%c", ans[i].y);
	printf("\n");
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define x first
#define y second
VI a[26], q[26];
char s[2222];
int n, k, m;
int main() {
	scanf("%d", &k);
	scanf("%s", s);
	n = (int)strlen(s);
	for(int j = 0; j < n; ++j)
		for(int i = 0; i < k; ++i)
			a[s[j] - 'a'].pb(j + n * i);
	scanf("%d", &m);
	for(int i = 0; i < m; ++i) {
		char who; int pos;
		scanf("%d %c", &pos, &who);
		--pos;
		q[who - 'a'].pb(pos);
	}
	vector<pair<int, char> > ans(0);
	for(int let = 0; let < 26; ++let) {
		for(int i = 0; i < L(q[let]); ++i)
			for(int j = 0; j < i; ++j)
				if (q[let][j] <= q[let][i]) q[let][i]++;
		int pos = 0;
		for(int i = 0; i < L(a[let]); ++i) {
			while(pos < L(q[let]) && q[let][pos] < i) ++pos;
			if (pos < L(q[let]) && q[let][pos] == i) continue;
			else ans.pb(mp(a[let][i], 'a' + let));
		}
	}
	sort(all(ans));
	for(int i = 0; i < L(ans); ++i) printf("%c", ans[i].y);
	printf("\n");
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define x first
#define y second
VI a[26], q[26];
char s[2222];
int n, k, m;
int main() {
	scanf("%d", &k);
	scanf("%s", s);
	n = (int)strlen(s);
	for(int i = 0; i < k; ++i)
		for(int j = 0; j < n; ++j)
			a[s[j] - 'a'].pb(j + n * i);
	scanf("%d", &m);
	for(int i = 0; i < m; ++i) {
		char who; int pos;
		scanf("%d %c", &pos, &who);
		--pos;
		q[who - 'a'].pb(pos);
	}
	vector<pair<int, char> > ans(0);
	for(int let = 0; let < 26; ++let) {
		for(int i = 0; i < L(q[let]); ++i) {
			a[let].erase(a[let].begin() + q[let][i]);
		}
		for(int i = 0; i < L(a[let]); ++i) {
			ans.pb(mp(a[let][i], 'a' + let));
		}
	}
	sort(all(ans));
	for(int i = 0; i < L(ans); ++i) printf("%c", ans[i].y);
	printf("\n");
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define x first
#define y second
VI a[26], q[26];
char s[2222];
int n, k, m;
int main() {
	scanf("%d", &k);
	scanf("%s", s);
	n = (int)strlen(s);
	for(int i = 0; i < k; ++i)
		for(int j = 0; j < n; ++j)
			a[s[j] - 'a'].pb(j + n * i);
	scanf("%d", &m);
	for(int i = 0; i < m; ++i) {
		char who; int pos;
		scanf("%d %c", &pos, &who);
		--pos;
		q[who - 'a'].pb(pos);
	}
	vector<pair<int, char> > ans(0);
	for(int let = 0; let < 26; ++let) {
		for(int i = 0; i < L(q[let]); ++i) {
			for(int j = 0; j < i; ++j)
				if (q[let][j] <= q[let][i]) q[let][i]++;
			int pos = i; while(pos && q[let][pos] < q[let][pos - 1]) { swap(q[let][pos], q[let][pos - 1]); --pos; }
		}
		int pos = 0;
		for(int i = 0; i < L(a[let]); ++i) {
			while(pos < L(q[let]) && q[let][pos] < i) ++pos;
			if (pos < L(q[let]) && q[let][pos] == i) continue;
			else ans.pb(mp(a[let][i], 'a' + let));
		}
	}
	sort(all(ans));
	for(int i = 0; i < L(ans); ++i) printf("%c", ans[i].y);
	printf("\n");
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <float.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)((s).size())
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define x first
#define y second
VI a[26], q[26];
char s[2222];
int n, k, m;
int main() {
	scanf("%d", &k);
	scanf("%s", s);
	n = (int)strlen(s);
	for(int j = 0; j < n; ++j)
		for(int i = 0; i < k; ++i)
			a[s[j] - 'a'].pb(j + n * i);
	scanf("%d", &m);
	for(int i = 0; i < m; ++i) {
		char who; int pos;
		scanf("%d %c", &pos, &who);
		--pos;
		q[who - 'a'].pb(pos);
	}
	vector<pair<int, char> > ans(0);
	for(int let = 0; let < 26; ++let) {
		for(int i = 0; i < L(q[let]); ++i) {
			a[let].erase(a[let].begin() + q[let][i]);
		}
		for(int i = 0; i < L(a[let]); ++i) {
			ans.pb(mp(a[let][i], 'a' + let));
		}
	}
	sort(all(ans));
	for(int i = 0; i < L(ans); ++i) printf("%c", ans[i].y);
	printf("\n");
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std ;
int main ()
{
	int k ;
	cin>>k ;
	string s;
	cin>>s;
	map<char,vector<int> > m ;
	int u = s.size();
	map<char,vector<int> >::iterator it ;
	pair<char,vector<int> >  p ;
	for ( int i = 0 ; i < u ; i ++ )
	{
		vector<int> v ;
		it = m.find(s[i]);
		if ( it == m.end() )
		{
			v.push_back(0);
			for ( int j = 0 ; j < k ; j ++ )
				v.push_back(-1);
			p = make_pair(s[i],v);
			m.insert(p);
		}
		else
			for ( int j = 0 ; j < k ; j ++ )
				(*it).second.push_back(-1);
	}
	int n ;
	cin>>n;
	int ind ;
	char c ;
	int z = 0 ;
	for ( int i = 0 ; i < n ; i ++ )
	{
		cin>>ind>>c;
		it = m.find(c);
		int q = (*it).second.size();
		if ( m.size() != 1 )
		for ( int j = 1 ; j < q ; j ++ )
		{
			if ( (*it).second[j] == -1 )
				ind -- ;
			if ( ind == 0 )
			{
				(*it).second[j] = -2 ;
				break ;
			}
		}
		else
			z ++ ;
	}
	if ( m.size() != 1 )
	for ( int r = 0 ; r < k ; r ++ )
	for ( int i = 0 ; i < u ; i ++ )
	{
		it = m.find(s[i]);
		(*it).second[0] ++ ;
		if ( (*it).second[(*it).second[0]] == -1 )
			cout<<s[i];
	}
	else
	{
		it = m.begin();
		int h = (*it).second.size();
		for( int i = 1 ; i < h-z ; i ++ )
			cout<<(*it).first;
	}
	cout<<endl;
	return 0 ;
}


#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<string>
#include<iomanip>
#include<math.h>
#include<cmath>
#include<queue>
#include<algorithm>
#include <stdio.h>
using namespace std ;
int main ()
{
	int k ;
	cin>>k;
	string s ;
	cin>>s;
	for ( int i = 1 ; i < k ; i ++ )
		s=s+s;
	int n ;
	cin>>n;
	int p , u , z = s.size() ;
	char c ;
	bool f ;
	for ( int i = 0 ; i < n ; i ++ )
	{
		cin>>p>>c;
		u = 0 ;
		f = false ;
		while ( p != 0 )
		{
			if ( s[u] == c )
			{
				p -- ;
				if ( p == 0 )
				{
					s[u] = '0' ;
					break ;
				}
			}
			u ++ ;
		}
	}
	for ( int i = 0 ; i < z ; i ++ )
		if ( s[i] != '0' )
			cout<<s[i];
	cout<<endl;
	return 0 ;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std ;
int main ()
{
    int k ;
    cin>>k;
    string s ;
    cin>>s;
    int n ;
    cin>>n;
    char a ;
    int b ;
    int in = 0 ;
    map<char,pair<int,vector<int> > > tree ;
    map<char,pair<int,vector<int> > >::iterator it ;
    for ( int i = 0 ; i < n ; i ++ )
    {
        cin>>b>>a;
        it = tree.find(a);
        if ( it == tree.end() )
        {
            vector<int> ind ;
            ind.push_back(b);
            pair<int,vector<int> > pp = make_pair(in,ind);
            pair<char,pair<int,vector<int> > > p = make_pair(a,pp);
            tree.insert(p);
        }
        else
            (*it).second.second.push_back(b);
    }
    int u = s.size();
    bool q ;
    for ( int r = 0 ; r < k ; r ++ )
        for ( int i = 0 ; i < u ; i ++ )
        {
            q = false ;
            it = tree.find(s[i]);
            if ( it != tree.end() )
            {
                (*it).second.first ++ ;
                int y = (*it).second.second.size();
                for ( int j = 0 ;  j < y ; j ++ )
                {
                    if ( (*it).second.first == (*it).second.second[j] )
                    {
                        (*it).second.second[j] = -100 ;
                        q = true ;
                        (*it).second.first -- ;
                        break ;
                    }
                }
            }
            if ( q == false )
                cout<<s[i];
        }
        cout<<endl;
        return 0 ;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std ;
int main ()
{
	int k ;
	cin>>k ;
	string s;
	cin>>s;
	map<char,vector<int> > m ;
	int u = s.size();
	map<char,vector<int> >::iterator it ;
	pair<char,vector<int> >  p ;
	for ( int i = 0 ; i < u ; i ++ )
	{
		vector<int> v ;
		it = m.find(s[i]);
		if ( it == m.end() )
		{
			v.push_back(0);
			for ( int j = 0 ; j < k ; j ++ )
				v.push_back(-1);
			p = make_pair(s[i],v);
			m.insert(p);
		}
		else
			for ( int j = 0 ; j < k ; j ++ )
				(*it).second.push_back(-1);
	}
	int n ;
	cin>>n;
	int ind ;
	char c ;
	for ( int i = 0 ; i < n ; i ++ )
	{
		cin>>ind>>c;
		it = m.find(c);
		int q = (*it).second.size();
		for ( int j = 1 ; j < q ; j ++ )
		{
			if ( (*it).second[j] == -1 )
				ind -- ;
			if ( ind == 0 )
			{
				(*it).second[j] = -2 ;
				break ;
			}
		}
	}
	for ( int r = 0 ; r < k ; r ++ )
	for ( int i = 0 ; i < u ; i ++ )
	{
		it = m.find(s[i]);
		(*it).second[0] ++ ;
		if ( (*it).second[(*it).second[0]] == -1 )
			cout<<s[i];
	}
	cout<<endl;
	return 0 ;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std ;
int main ()
{
    int k ;
    cin>>k;
    string s ;
    cin>>s;
    int n ;
    cin>>n;
    char a ;
    int b ;
    int in = 0 ;
    map<char,pair<int,vector<int> > > tree ;
    for ( int i = 0 ; i < n ; i ++ )
    {
        cin>>b>>a;
        map<char,pair<int,vector<int> > >::iterator it = tree.find(a);
        if ( it == tree.end() )
        {
            vector<int> ind ;
            ind.push_back(b);
            pair<int,vector<int> > pp = make_pair(in,ind);
            pair<char,pair<int,vector<int> > > p = make_pair(a,pp);
            tree.insert(p);
        }
        else
            (*it).second.second.push_back(b);
    }
    int u = s.size();
    bool q  ;
    for ( int r = 0 ; r < k ; r ++ )
        for ( int i = 0 ; i < u ; i ++ )
        {
            q = false ;
            map<char,pair<int,vector<int> > >::iterator it = tree.find(s[i]);
            if ( it != tree.end() )
            {
                (*it).second.first ++ ;
                int y = (*it).second.second.size();
                for ( int j = 0 ;  j < y ; j ++ )
                {
                    if ( (*it).second.first == (*it).second.second[j] )
                    {
                        (*it).second.second[j] = -100 ;
                        q = true ;
                        (*it).second.first -- ;
                        break ;
                    }
                }
            }
            if ( q == false )
                cout<<s[i];
        }
        cout<<endl;
        return 0 ;
}


#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std ;
int main ()
{
    int k ;
    cin>>k;
    string s ;
    cin>>s;
    int n ;
    cin>>n;
    char a ;
    int b ;
    int in = 0 ;
    map<char,pair<int,vector<int> > > tree ;
    for ( int i = 0 ; i < n ; i ++ )
    {
        cin>>b>>a;
        map<char,pair<int,vector<int> > >::iterator it = tree.find(a);
        if ( it == tree.end() )
        {
            vector<int> ind ;
            ind.push_back(b);
            pair<int,vector<int> > pp = make_pair(in,ind);
            pair<char,pair<int,vector<int> > > p = make_pair(a,pp);
            tree.insert(p);
        }
        else
            (*it).second.second.push_back(b);
    }
    int u = s.size();
    bool q  ;
    for ( int r = 0 ; r < k ; r ++ )
        for ( int i = 0 ; i < u ; i ++ )
        {
            q = false ;
            map<char,pair<int,vector<int> > >::iterator it = tree.find(s[i]);
            if ( it != tree.end() )
            {
                (*it).second.first ++ ;
                int y = (*it).second.second.size();
                for ( int j = 0 ;  j < y ; j ++ )
                {
                    if ( (*it).second.first == (*it).second.second[j] )
                    {
                        (*it).second.second[j] = 0 ;
                        q = true ;
                        (*it).second.first -- ;
                        break ;
                    }
                }
            }
            if ( q == false )
                cout<<s[i];
        }
        cout<<endl;
        return 0 ;
}


//IN THE NAME OF GOD
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <fstream>
#include <utility>
#include <sstream>
#include <list>
#include <iomanip>
#include <functional>
#include <deque>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <complex>
#include <climits>
#include <cctype>
#include <cassert>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std ;

#define timestamp(x) printf("Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define INF 0x3f3f3f3f
#define pii pair < int , int >
#define MP make_pair
#define MOD 1000000007
#define EPS 1e-9

map < char , vector < int > > ind ;
map < char , int > pl ;

int main ()
{
    //freopen ( "i.txt" , "r" , stdin ) ;
    string line , tmp ;
    int k , m ;
    char ch ;
    cin >> k ;
    getline ( cin , line ) ;
    getline ( cin , line ) ;
    tmp = line ;
    for ( int i = 0 ; i < k-1 ; i++ ) line += tmp ;
    for ( int i = 0 ; i < line.size() ; i++ ){
        ind[line[i]].push_back ( i ) ;
        pl[line[i]] = 0 ;
    }
    cin >> m ;
    while ( m-- ){
        cin >> k >> ch ;
        line[ind[ch][k+pl[ch]-1]] = '#' ;
        pl[ch]++ ;
    }
    for ( int i = 0 ; i < line.size() ; i++ ){
        if ( line[i] != '#' )
            cout << line[i] ;
    }
    cout << endl ;
    return 0 ;
}


//IN THE NAME OF GOD
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <fstream>
#include <utility>
#include <sstream>
#include <list>
#include <iomanip>
#include <functional>
#include <deque>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <complex>
#include <climits>
#include <cctype>
#include <cassert>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std ;

#define timestamp(x) printf("Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define INF 0x3f3f3f3f
#define pii pair < int , int >
#define MP make_pair
#define MOD 1000000007
#define EPS 1e-9

map < char , vector < int > > ind ;
map < char , int > pl ;

int main ()
{
    //freopen ( "i.txt" , "r" , stdin ) ;
    string line = "" , tmp ;
    int k , m ;
    char ch ;
    cin >> k ;
    getline ( cin , line ) ;
    getline ( cin , tmp ) ;
    for ( int i = 0 ; i < k ; i++ ) line += tmp ;
    for ( int i = 0 ; i < line.size() ; i++ ){
        ind[line[i]].push_back ( i ) ;
        pl[line[i]] = 0 ;
    }
    cin >> m ;
    while ( m-- ){
        cin >> k >> ch ;
        line[ind[ch][k-1]] = '#' ;
        ind[ch].erase ( ind[ch].begin() + k - 1 ) ;
    }
    for ( int i = 0 ; i < line.size() ; i++ ){
        if ( line[i] != '#' )
            cout << line[i] ;
    }
    cout << endl ;
    return 0 ;
}


//IN THE NAME OF GOD
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <fstream>
#include <utility>
#include <sstream>
#include <list>
#include <iomanip>
#include <functional>
#include <deque>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <complex>
#include <climits>
#include <cctype>
#include <cassert>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std ;

#define timestamp(x) printf("Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define INF 0x3f3f3f3f
#define pii pair < int , int >
#define MP make_pair
#define MOD 1000000007
#define EPS 1e-9

map < char , vector < int > > ind ;
map < char , int > pl ;

int main ()
{
   // freopen ( "i.txt" , "r" , stdin ) ;
    string line = "" , tmp ;
    int k , m ;
    char ch ;
    cin >> k ;
    getline ( cin , line ) ;
    getline ( cin , tmp ) ;
    for ( int i = 0 ; i < k ; i++ ) line += tmp ;
    for ( int i = 0 ; i < line.size() ; i++ ){
        ind[line[i]].push_back ( i ) ;
        pl[line[i]] = 0 ;
    }
    cin >> m ;
    while ( m-- ){
        cin >> k >> ch ;
        line[ind[ch][k+pl[ch]-1]] = '#' ;
        pl[ch]++ ;
    }
    for ( int i = 0 ; i < line.size() ; i++ ){
        if ( line[i] != '#' )
            cout << line[i] ;
    }
    cout << endl ;
    return 0 ;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
	int k;
	string s;
	cin >> k;
	cin.ignore();
	getline(cin, s);
	string t = "";
	for (int i = 0; i < k; i++)
		t += s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int p;
		char c;
		cin >> p >> c;
		string subs = t;
		int pos2 = subs.find(c) + 1;
		subs = subs.substr(pos2);
		for (int j = 1; j < p; j++)
		{
			int pos = subs.find(c);
			pos2 += pos + 1;
			subs = subs.substr(pos + 1);
		}
		t = t.substr(0, pos2 - 1) + t.substr(pos2);
	}
	cout << t << endl;
}


#include <iostream>
#include <string>

using namespace std;
int pos[36][200010];
void Shift (int *pos, int start, int end)
{
	for (int i = start; i < end; i++)
		pos[i] = pos[i + 1];
	pos[end] = -1;
}
int main()
{
	int k;
	string s;
	cin >> k;
	cin.ignore();
	getline(cin, s);
	string t = "";
	int max[36] = {0};
	for (int i = 0; i < k; i++)
	{
		for (int j = 0; j < s.length(); j++)
		{
			pos[s[j] - 'a'][max[s[j] - 'a']++] = i * s.length() + j;
		}
		t += s;
	}
	int maxln = t.length();
	int n;
	cin >> n;
	int del[200000] = {0};
	for (int i = 0; i < n; i++)
	{
		int p;
		char c;
		cin >> p >> c;
		int pos2 = pos[c - 'a'][p - 1];
		Shift(pos[c - 'a'], p - 1, max[c - 'a'] - 1);
		max[c - 'a']--;
		t[pos2] = 0;
	}
	for (int i = 0; i < t.length(); i++)
		if (t[i] != 0)
			cout << t[i];
	cout << endl;
}


#include <iostream>
#include <algorithm>

using namespace std;

struct pt{
	int a, b;
	bool operator < (pt a2)
	{
		return a < a2.a || (a == a2.a && b < a2.b);
	}
};
int main()
{
	pt marker[10000], cap[10000];
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> marker[i].a >> marker[i].b;
	sort(marker, marker + n);
	for (int i = 0; i < m; i++)
		cin >> cap[i].a >> cap[i].b;
	sort(cap, cap + m);
	int i = 0, j = 0, closed = 0, beautiful = 0;
	while(i < n && j < m)
	{
		if (marker[i].b < cap[j].b)
		{
			i++;
			continue;
		}
		if (cap[j].b < marker[i].b)
		{
			j++;
			continue;
		}
		closed++;
		if (cap[j].a == marker[i].a)
			beautiful++;
		else if (cap[j + 1].b == cap[j].b)
			j--;
		i++, j++;
	}
	cout << closed << " " << beautiful << endl;

}


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

using namespace std;

char t[2005][105];
int sum[2005][26];

int main(){
	int n, k, p;
	char q;
	cin >> k;
	string s;
	cin >> s;
	int len = s.length();
	for (int i = 0; i < len; ++i){
		sum[0][s[i] - 'a']++;
	}
	for (int i = 1; i < k; ++i){
		for (int j = 0; j < len; ++j){
			sum[i][j] = sum[0][j];
		}
	}
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> p >> q;
		int line = 0, ss = 0;
		for(;;line++){
			if (ss + sum[line][q - 'a'] >= p)
				break;
			else
				ss += sum[line][q - 'a'];
		}
		for (int j = 0; j < len; ++j){
			if (s[j] == q && !t[line][j]){
				ss++;
				if (ss == p){
					t[line][j] = 1;
					sum[line][q - 'a'] -= 1;
					break;
				}
			}
		}
	}
	for (int i = 0; i < k; ++i){
		for (int j = 0; j < len; ++j)
			if (!t[i][j])
				cout << s[j];
	}
	cout << endl;
	return 0;
}


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

using namespace std;

char t[2005][105];
char s[105];
int sum[2005][30];

int main(){
	int n, k, p;
	scanf("%d\n", &k);
	char q;
	int len = 0;
	scanf("%c", &q);
	while (q != '\n'){
		s[len++] = q;
		scanf("%c", &q);
	}
	for (int i = 0; i < len; ++i){
		sum[0][s[i] - 'a']++;
	}
	for (int i = 1; i < k; ++i){
		for (int j = 0; j < len; ++j){
			sum[i][j] = sum[0][j];
		}
	}
	scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		scanf("%d %c", &p, &q);
		int line = 0, ss = 0;
		for(;line < k;line++){
			if (ss + sum[line][q - 'a'] >= p)
				break;
			else
				ss += sum[line][q - 'a'];
		}
		for (int j = 0; j < len; ++j){
			if (s[j] == q && !t[line][j]){
				ss++;
				if (ss == p){
					t[line][j] = 1;
					sum[line][q - 'a'] -= 1;
					break;
				}
			}
		}
	}
	for (int i = 0; i < k; ++i){
		for (int j = 0; j < len; ++j)
			if (!t[i][j])
				printf("%c", s[j]);
	}
	printf("\n");
	return 0;
}


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

using namespace std;

char t[2005][105];
char s[105];
int sum[2005][30];

int main(){
	int n, k, p;
	scanf("%d\n", &k);
	char q;
	int len = 0;
	scanf("%c", &q);
	while (q != '\n'){
		s[len++] = q;
		scanf("%c", &q);
	}
	for (int i = 0; i < len; ++i){
		sum[0][s[i] - 'a']++;
	}
	for (int i = 1; i < k; ++i){
		for (int j = 0; j < 26; ++j){
			sum[i][j] = sum[0][j];
		}
	}
	scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		scanf("%d %c", &p, &q);
		int line = 0, ss = 0;
		for(;line < k;line++){
			if (ss + sum[line][q - 'a'] >= p)
				break;
			else
				ss += sum[line][q - 'a'];
		}
		for (int j = 0; j < len; ++j){
			if (s[j] == q && !t[line][j]){
				ss++;
				if (ss == p){
					t[line][j] = 1;
					sum[line][q - 'a'] -= 1;
					break;
				}
			}
		}
	}
	for (int i = 0; i < k; ++i){
		for (int j = 0; j < len; ++j)
			if (!t[i][j])
				printf("%c", s[j]);
	}
	printf("\n");
	return 0;
}


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

using namespace std;

char t[2005][105];
char s[105];
int sum[2005][26];

int main(){
	int n, k, p;
	scanf("%d\n", &k);
	char q;
	int len = 0;
	scanf("%c", &q);
	while (q != '\n'){
		s[len++] = q;
		scanf("%c", &q);
	}
	for (int i = 0; i < len; ++i){
		sum[0][s[i] - 'a']++;
	}
	for (int i = 1; i < k; ++i){
		for (int j = 0; j < len; ++j){
			sum[i][j] = sum[0][j];
		}
	}
	scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		scanf("%d %c", &p, &q);
		int line = 0, ss = 0;
		for(;;line++){
			if (ss + sum[line][q - 'a'] >= p)
				break;
			else
				ss += sum[line][q - 'a'];
		}
		for (int j = 0; j < len; ++j){
			if (s[j] == q && !t[line][j]){
				ss++;
				if (ss == p){
					t[line][j] = 1;
					sum[line][q - 'a'] -= 1;
					break;
				}
			}
		}
	}
	for (int i = 0; i < k; ++i){
		for (int j = 0; j < len; ++j)
			if (!t[i][j])
				printf("%c", s[j]);
	}
	printf("\n");
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>

#define pb push_back
#define rep(i,d,n) for(int (i) = (d); (i) < (n); (i)++)
using namespace std;
typedef pair<int,int> II;
int n,k,m;
int Min(int a, int b)
{
	if(a<b) return a;
	else return b;
}
vector<vector<int>> act = vector<vector<int>>(50,vector<int>(0,0));
vector<string> res;
vector<vector<int>> nres;
vector<int> temp = vector<int>(26,0);
string s;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int f = 0;
	char d = 0;
	int fuuu = 0;
	cin >> k;
	cin >> s;
	cin >> n;

	rep(i,0,k)
		res.pb(s);
	d = s.size();
	rep(i,0,d)
		temp[s[i]-'a']++;
	rep(i,0,k)
		nres.pb(temp);

	rep(i,0,n)
	{
		cin >> f >> d;
		d -= 'a';
		act[d].pb(f);
	}

	int lenn = 0;
	int te = 0;
	rep(i,0,26)
	{
		lenn = act[i].size();
		rep(j,0,lenn)
		{
			f = 0;
			fuuu = 0;
			while(fuuu < act[i][j])
			{
				fuuu+=nres[f][i];
				f++;
			}
			f--;
			fuuu-= nres[f][i];
			n = res[f].length();
			te = 0;
			rep(p,0,n)
			{

				if((res[f][p]-'a') == i)
				{
					if(te+fuuu+1 == act[i][j])
					{
						res[f].erase(res[f].begin()+p);
						nres[f][i]--;
						break;
					}
					else
						te++;
				}
			}
		}

	}
	n = res.size();
	rep(i,0,n)
	cout << res[i];
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>

#define pb push_back
#define rep(i,d,n) for(int (i) = (d); (i) < (n); (i)++)
using namespace std;
typedef pair<int,int> II;
int n,k,m;
int Min(int a, int b)
{
	if(a<b) return a;
	else return b;
}
vector<vector<int>> act = vector<vector<int>>(50,vector<int>(0,0));
vector<string> res;
vector<vector<int>> nres;
vector<int> temp = vector<int>(26,0);
string s;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int f = 0;
	char d = 0;
	cin >> k;
	cin >> s;
	cin >> n;

	rep(i,0,k)
		res.pb(s);
	d = s.size();
	rep(i,0,d)
		temp[s[i]-'a']++;
	rep(i,0,k)
		nres.pb(temp);

	rep(i,0,n)
	{
		cin >> f >> d;
		d -= 'a';
		act[d].pb(f);
	}
	string::iterator bg;
	int lenn = 0;
	int te = 0;
	rep(i,0,26)
	{
		f = 1;
		d = 0;
		lenn = act[i].size();
		rep(j,0,lenn)
		{
			f = 0;
			d = 0;
			while(d < act[i][j])
			{
				d+=nres[f][i];
				f++;
			}
			f--;
			d-= nres[f][i];
			n = res[f].length();
			rep(p,0,n)
			{
				te = 0;
				if((res[f][p]-'a') == i)
				{
					if(te+d+1 == act[i][j])
					{
						res[f].erase(res[f].begin()+p);
						nres[f][i]--;
						break;
					}
					else
						te++;
				}
			}
		}

	}
	n = res.size();
	rep(i,0,n)
	cout << res[i];
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>

#define pb push_back
#define rep(i,d,n) for(int (i) = (d); (i) < (n); (i)++)
using namespace std;
typedef pair<int,int> II;
int n,k,m;
int Min(int a, int b)
{
	if(a<b) return a;
	else return b;
}
vector<vector<int>> act = vector<vector<int>>(50,vector<int>(0,0));
vector<string> res;
vector<vector<int>> nres;
vector<int> temp = vector<int>(26,0);
string s;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int f = 0;
	char d = 0;
	cin >> k;
	cin >> s;
	cin >> n;

	rep(i,0,k)
		res.pb(s);
	d = s.size();
	rep(i,0,d)
		temp[s[i]-'a']++;
	rep(i,0,k)
		nres.pb(temp);

	rep(i,0,n)
	{
		cin >> f >> d;
		d -= 'a';
		act[d].pb(f);
	}
	string::iterator bg;
	int lenn = 0;
	int te = 0;
	rep(i,0,26)
	{
		f = 1;
		d = 0;
		lenn = act[i].size();
		rep(j,0,lenn)
		{
			f = 0;
			d = 0;
			while(d < act[i][j])
			{
				d+=nres[f][i];
				f++;
			}
			f--;
			d-= nres[f][i];
			n = res[f].length();
			te = 0;
			rep(p,0,n)
			{

				if((res[f][p]-'a') == i)
				{
					if(te+d+1 == act[i][j])
					{
						res[f].erase(res[f].begin()+p);
						nres[f][i]--;
						break;
					}
					else
						te++;
				}
			}
		}

	}
	n = res.size();
	rep(i,0,n)
	cout << res[i];
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
set<int> stk[30];
set<int> ::iterator sit;
set<int> ::reverse_iterator rsit;
int rec[30];
char ans[2010][110];
int main ()
{
    //freopen ("2.txt", "r", stdin);
    //freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        for (i = 0; i < 26; i ++) stk[i].clear();
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[4];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (sit = stk[num].begin(); sit != stk[num].end(); sit ++)
                if (*sit <= loc)
                    loc ++;
                else
                    break;
            stk[num].insert(loc);
        }

        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (rsit = stk[i].rbegin(); rsit != stk[i].rend(); rsit ++)
            {
                int num = *rsit;
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] - 'a' == i)
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    printf ("%c", ans[i][j]);
        printf ("\n");
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
//  freopen ("2.txt", "r", stdin);
//  freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[2];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }
        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);
        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] - 'a' == i)
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    //printf ("%c", ans[i][j]);
                    cout << ans[i][j];
 }}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
//  freopen ("2.txt", "r", stdin);
//  freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[2];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }
        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);
        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] - 'a' == i)
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    //printf ("%c", ans[i][j]);
                    cout << ans[i][j];
        printf ("\n");
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
    //freopen ("2.txt", "r", stdin);
    //freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[2];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }
        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);
        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] == i + 'a')
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    printf ("%c", ans[i][j]);
        printf ("\n");
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
    //freopen ("2.txt", "r", stdin);
//  freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[2];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }
        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);
        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] == i + 'a')
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    printf ("%c", ans[i][j]);
        printf ("\n");
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
    freopen ("2.txt", "r", stdin);
    freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[2];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }
        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);
        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] == i + 'a')
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    printf ("%c", ans[i][j]);
        printf ("\n");
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
//  freopen ("2.txt", "r", stdin);
//  freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[4];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }

        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);

        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] - 'a' == i)
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    printf ("%c", ans[i][j]);
        printf ("\n");
    }
}


#include <iostream>
#include <string>
#i#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
    //freopen ("2.txt", "r", stdin);
//  freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[2];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }
        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);
        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] == i + 'a')
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    printf ("%c", ans[i][j]);
        printf ("\n");
    }
}


#include <iostream>
#include <string>
#i#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, K;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
//  freopen ("2.txt", "r", stdin);
//  freopen ("3.txt", "w", stdout);
    while (scanf ("%d", &K) != EOF)
    {
        int i, j, k;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[2];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }
        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);
        for (i = 0; i < K; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] - 'a' == i)
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < K; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    //printf ("%c", ans[i][j]);
                    cout << ans[i][j];
        printf ("\n");
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int n, k;
char s[110];
int stk[30][21000];
int top[30];
int rec[30];
char ans[2010][110];
int main ()
{
    while (scanf ("%d", &k) != EOF)
    {
        int i, j;
        scanf ("%s", s);
        scanf ("%d", &n);
        memset (top, 0, sizeof(top));
        memset (rec, 0, sizeof(rec));
        for (i = 0; i < n; i ++)
        {
            char stemp[2];
            int loc;
            scanf ("%d%s", &loc, stemp);
            int num = stemp[0] - 'a';
            for (j = 0; j < top[num]; j ++)
                if (stk[num][j] <= loc)
                    loc ++;
            stk[num][top[num] ++] = loc;
        }
        for (i = 0; i < 26; i ++)
            sort(stk[i], stk[i] + top[i]);
        for (i = 0; i < k; i ++)
            strcpy(ans[i], s);

        for (i = 0; i < strlen(s); i ++)
            rec[s[i] - 'a'] ++;

        int len = strlen(s);
        for (i = 0; i < 26; i ++)
            for (j = top[i] - 1; j >= 0; j --)
            {
                int num = stk[i][j];
                num --;
                int p = num / rec[i];
                int q = num % rec[i];
                int temp = 0;
                for (k = 0; k < len; k ++)
                    if (ans[p][k] == i + 'a')
                    {
                        if (temp == q)
                        {
                            ans[p][k] = 0;
                            break;
                        }
                        temp ++;
                    }
            }
        for (i = 0; i < k; i ++)
            for (j = 0; j < len; j ++)
                if (ans[i][j] != 0)
                    printf ("%c", ans[i][j]);
        printf ("\n");
    }
}


#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <cmath>
#include <sstream>
#include <ctime>
#include <memory.h>
#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define forv(i, a) for(int i=0; i<(int)a.size(); i++)
#define mset(a, val) memset(a, val, sizeof(a))
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define VI vector< int >
#define VS vector< string >
#define PII pair< int,int >
#define PDD pair< double,double >
#define PIS pair< int, string >
#define sqr(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define pi 3.1415926535897932384626433832795
#define PI pi
#define iinf 1000000000
#define sinf 10000
#define eps 1e-12
#define lng long long
#define X first
#define Y second
using namespace std;
#define prev asdprev
#define exit(a) { if (a) cerr<<"oops "<<a<<endl; exit(a); }

#define max(a, b) ((a>b)?a:b)

int segtree[800000];
int len;

void build(int i=1, int tl=1, int tr=len){
    if(tl==tr) segtree[i]=1;
    else{
        int tc=(tl+tr)/2;

        build(i*2, tl, tc);
        build(i*2+1, tc+1, tr);

        segtree[i]=segtree[i*2]+segtree[i*2+1];
    }
}

void setnul(int pos, int i=1, int tl=1, int tr=len){
    if(tl==tr && tl==pos){
        segtree[i]=0;
        return;
    }

    int tc=(tl+tr)/2;

    if(pos<=tc) setnul(pos, i*2, tl, tc);
    else setnul(pos, i*2+1, tc+1, tr);
    segtree[i]=segtree[i*2]+segtree[i*2+1];
}

int get(int r, int l=1, int i=1, int tl=1, int tr=len){
    if(tl==l && tr==r) return segtree[i];

    int tc=(tl+tr)/2;
    if(r<=tc) return get(r, l, i*2, tl, tc);
    else if(l>tc) return get(r, l,  i*2+1, tc+1, tr);
    else{
        return get(tc, l,  i*2, tl, tc) + get(r, tc+1,  i*2+1, tc+1, tr);
    }
}

int findit(int x){
    int b=1, e=len;

    while(b<e){
        int m=(b+e)/2;

        int cur=get(m);
        if(cur==x) e=m;
        else if(cur<x) b=m+1;
        else e=m-1;
    }
    return b;
}

char str[300000];
int del[26][20000];
int delcnt[26];
bool deleted[300000];

#define taska "intersection"
int main() {
#ifdef __ASD__
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#else
    //freopen(taska".in", "r", stdin);freopen(taska".out", "w", stdout); freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#endif

    int n, k;
    string s;
    cin>>k;
    cin>>s;

    len=(int)s.size();
    forn(i, k){
        forv(j, s)
            str[i*len+j]=s[j];
    }

    len*=k;

    cin>>n;
    forn(i, n){
        int p;
        char c;

        cin>>p>>c;

        del[c-'a'][delcnt[c-'a']++]=p;
    }

    forn(ch, 26){
        build();
        mset(deleted, 0);

        forn(i, delcnt[ch]){
            int pos=findit(del[ch][i]);
            del[ch][i]=pos;

            setnul(pos);
            deleted[pos]=true;
        }

        int cnt=0;
        if(delcnt[ch]>0)
        forn(i, len)
            if(str[i]==ch+'a'){
                ++cnt;
                if(deleted[cnt]) str[i]='!';
            }

    }

    forn(i, len)
        if(str[i]!='!') printf("%c", str[i]);

    return 0;
}