#include <bits/stdc++.h>
using namespace std;
vector<int> vis,pre,nex;
int n;
void print_helper(int a,int b){
if(a==0||a==n+1)
cout<<"* ";
else cout<<a<<' ';
if(b==0||a==n+1)
cout<<"*";
else cout<<b;
cout<<endl;
}
int main(){
ios::sync_with_stdio(0);
int q;
while(cin>>n>>q){
if(n==0&&q==0)return 0;
vis.assign(n+2,0);
pre.assign(n+2,0);
nex.assign(n+2,0);
for(int i=1;i<=n;i++){
pre[i]=i-1;
nex[i]=i+1;
}
pre[1]=nex[n]=pre[0]=nex[n+1]=0;
for(int i=0;i<q;i++){
int l,r;
cin>>l>>r;
print_helper(pre[l],nex[r]);
nex[pre[l]]=nex[r];
pre[nex[r]]=pre[l];
}
cout<<'-'<<endl;
}
return 0;
}
Comments
Post a Comment