#include <map>
#include <iostream>
#include <iterator>
using namespace std;
int main(){
    int q,k;
    string s;
    map<string,int>m;
    map<string,int>::iterator u,v;
    cin>>q;
    while(q--){
        cin>>k>>s;
        if(k==0){
            cin>>k;
            if(m.find(s)!=m.end())m[s]=k;
            else m.insert({s,k});
        }
        else if(k==1){
            if(m.find(s)!=m.end())cout<<m[s]<<endl;
            else cout<<0<<endl;
        }
        else if(k==2)m.erase(s);
        else{
            u=m.lower_bound(s);
            cin>>s;
            while(u!=m.end()){
                if(u->first>s)break;
                cout<<u->first<<' '<<u->second<<endl;
                u++;
            }
        }
    }
}
