#include <bits/stdc++.h>
using namespace std;
bool viss[1010];
int main(){
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    int t;
    cin >> t;
    int n,m,k;
    cin >> n >> m >> k;
    int arr[m];
    map<int,int> vis;
    for(int i=0;i<m;i++){
        cin >> arr[i];
        //
        /*
        for(int j=1;j<=n;j++){
        	cout << viss[j] << " "; 
		}
		cout << endl;
		*/
		//
        if(vis[arr[i]]!=0){
            cout << 1 << " " << vis[arr[i]] << endl;
            viss[vis[arr[i]]]=0;
            vis[arr[i]]=0;
            continue;
        }
        for(int j=1;j<=n;j++){
            if(viss[j]==0){
                viss[j]=1;
                vis[arr[i]]=j;
                cout << 1 << " " << vis[arr[i]] << endl;
                break;
            }
        }
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
