set搞之……
/*
* Author: stormdpzh
* Created Time: 2012/7/22 23:35:15
* File Name: poj_2051.cpp
*/
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#define sz(v) ((int)(v).size())
#define rep(i, n) for(int i = 0; i < n; i++)
#define repf(i, a, b) for(int i = a; i <= b; i++)
#define repd(i, a, b) for(int i = a; i >= b; i--)
#define out(n) printf("%d\n", n)
#define mset(a, b) memset(a, b, sizeof(a))
#define wh(n) while(1 == scanf("%d", &n))
#define whz(n) while(1 == scanf("%d", &n) && n != 0)
#define lint long long
using namespace std;
const int MaxN = 1 << 30;
struct Node {
int ttime;
int period;
int id;
Node(int _ttime, int _period, int _id) : ttime(_ttime), period(_period), id(_id) {}
bool operator < (const Node &t) const {
if(ttime == t.ttime) return id < t.id;
return ttime < t.ttime;
}
};
set<Node> st;
char s[20];
int id, period;
int n;
void gao()
{
while(n--) {
set<Node>::iterator it = st.begin();
printf("%d\n", it->id);
st.insert(Node(it->ttime + it->period, it->period, it->id));
st.erase(it);
}
}
int main()
{
while(1 == scanf("%s", s)) {
if(s[0] == '#') break;
scanf("%d%d", &id, &period);
st.insert(Node(period, period, id));
}
scanf("%d", &n);
gao();
return 0;
}