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

public class Rvq implements Runnable {

	final String fName = "rvq";
    final int MAX_N = 100000;

    Scanner in;
    PrintWriter out;


    int nextInt ( StreamTokenizer in ) throws Exception {
        in.nextToken();
        return (int)in.nval;
    }

    class Node{
        long min, max;
        int bs, es;
        Node l;
        Node r;

        Node(long[] values, int bs, int es) {
            this.bs = bs;
            this.es = es;
            if (bs == es) {
                min = max = values[bs];
                l = r = null;
            } else {
                l = new Node(values, bs, (bs + es) / 2);
                r = new Node(values, (bs + es) / 2 + 1, es);
                min = Math.min(l.min, r.min);
                max = Math.max(l.max, r.max);
            }
        }

        long getMax(int b, int e){
            //System.out.println(bs + " " + es);
            if ( b > es || e < bs ) return Long.MIN_VALUE;
            if ( b <= bs && e >= es ) return max;
            return Math.max( l.getMax(b, e), r.getMax(b, e) );
        }

        long getMin(int b, int e){
            if ( b > es || e < bs ) return Long.MAX_VALUE;
            if ( b <= bs && e >= es ) return min;
            return Math.min( l.getMin(b, e), r.getMin(b, e) );
        }

        void update(int pos, long v){
            if (pos < bs || pos > es) return;
            if (es == bs) {
                min = max = v;
            } else {
                l.update(pos, v);
                r.update(pos, v);
                min = Math.min(l.min, r.min);
                max = Math.max(l.max, r.max);
            }
        }
    }

    public void run() {
        try {
            //StreamTokenizer in = new StreamTokenizer( new BufferedReader( new FileReader( new File( fName + ".out" ) ) ) );
            long startTime = System.nanoTime();
            in = new Scanner( new File( fName + ".in" ) );
            out = new PrintWriter( new File( fName + ".out" ) );
            long[] a = new long[MAX_N + 1];
            for(int i = 1; i <= MAX_N; i++){
                a[i] = ( 1L * i * i ) % 12345 + (1L * i * i * i) % 23456;
            }
            Node tree = new Node(a, 1, MAX_N);
            int n = in.nextInt();
            for(int i = 0; i < n; i++){
                int b = in.nextInt();
                int e = in.nextInt();
                if (b > 0) {
//                    System.out.println( "get " + (b - 1) + " " + (e - 1) );
//                    System.out.println( tree.getMax(b - 1, e - 1) );
//                    System.out.println( tree.getMin(b - 1, e - 1) );
                    out.println( tree.getMax(b, e) - tree.getMin(b, e) );
                } else {
                    //System.out.println( " get " + (-b) + "; " + e);
                    tree.update( -b, e);
                }
            }
            out.close();
            long endTime = System.nanoTime();
            //System.out.println( 1.0 * ( endTime - startTime ) / 1e9 );
        } catch ( Exception e ) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static void main( String[] args ){
        new Thread( new Rvq() ).start();
    }
}
