#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include <climits>
#include<cstdio>
using namespace std;

int main()
{
	string a[10240] = {};
	int next1[10240] = {};
	char b[12040] = {};
	char tmp[10240] = {};
	next1[0] = 0;

	long long k = 1;

	
	int flag = 0;
	while (gets(b)){
		long long l = 0;
		long long sum = 0;
		if (b[0] == '0'&&strlen(b) == 1){
			break;
		}
	
		for (int i = 0; b[i]; i++){
			if (b[i] >= 'a'&&b[i] <= 'z' || (b[i] >= 'A'&&b[i] <= 'Z'))
			{
				cout << b[i];
				tmp[l] = b[i];
				l++;
				if (b[i + 1] == '\0'){
					if (tmp[0]){
						a[k] = tmp;
						next1[k] = next1[0];
						next1[0] = k;
						k++;
						l = 0;
						memset(tmp, 0, sizeof(tmp));
					}
				}
			}
			else if (b[i] >= '0'&&b[i] <= '9'){
				sum = sum * 10 + b[i] - '0';
				if (b[i + 1] == '\0' || b[i + 1]<'0' || b[i]>'9'){
					int ti = 1;
					int ch = 0;
					for (int w = next1[0]; w != 0; w = next1[w]){
						if (ti == sum){
							cout << a[w];
							ch = w;
							break;
						}
						ti++;
					}
					int no;
					if (sum!= 1&&sum!=0){
						for (int w = next1[0]; w != 0; w = next1[w]){
							if (next1[w] == ch){
								no = w;
								break;
							}
						}
						next1[no] = next1[ch];
						next1[ch] = next1[0];
						next1[0] = ch;
					}
					sum = 0;
				}
			}
			else{
				cout << b[i];
				if (tmp[0]){
					a[k] = tmp;
					next1[k] = next1[0];
					next1[0] = k;
					k++;
					l = 0;
					memset(tmp, 0, sizeof(tmp));
				}
			}
		}
		cout << endl;
	}
	return 0;
}