import java.util.*;
import java.io.*;

class rvq implements Runnable{
    long Max(long[] mas, int b, int e){
      long max = mas[b];
      for(int i = b; i <= e;i++)
        if(mas[i]>max)
         max=mas[i];
      return max;
    }

   long Min(long[] mas, int b, int e){
       long min = mas[b];
      for(int i = b; i <= e;i++)
        if(mas[i] < min)
         min = mas[i];
      return min;
    }
    public void run(){
       try{
           Scanner in = new Scanner(new File("rvq.in"));
           PrintWriter out = new PrintWriter(new File("rvq.out"));

           int n =in.nextInt();
           long[] l = new long[100000];
           for(int j = 0; j <100000; j++){
             long k = j*j;
             long k1 = k % 12345;
             long k2 = (k*j) % 23456;
             l[j]= k1 + k2;
          }

           for(int i = 0; i < n; i++){
               int x = in.nextInt();
               int y = in.nextInt();
               if(x>=0){
                 long max = Max(l,x,y);
                long min = Min(l,x,y);
                 out.println(max - min);
               }
              else{
                 x=0-x;
                 l[x]=y;
               }
           }

           in.close();
           out.close();
       }  catch(Exception e){
               e.printStackTrace();
               System.exit(1);
          }
     }
     public static void main(String[] args) {
       new Thread(new rvq()).start();
    }
}
