public static void main ( String [ ] args ) {
  FastScanner sc = new FastScanner ( ) ;
  int t = sc . nextInt ( ) ;
  while ( t -- > 0 ) {
    int INF = ( int ) 1e9 ;
    int n = sc . nextInt ( ) , x = sc . nextInt ( ) , m = sc . nextInt ( ) , mini = x , maxi = x ;
    while ( m -- > 0 ) {
      int l = sc . nextInt ( ) , r = sc . nextInt ( ) ;
      if ( ( l <= maxi ) && ( r >= mini ) ) {
        maxi = Math . max ( maxi , r ) ;
        mini = Math . min ( mini , l ) ;
      }
    }
    System . out . println ( maxi - mini + 1 ) ;
  }
}

public static void main ( String [ ] args ) { FastScanner sc = new FastScanner ( ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int INF = ( int ) 1e9 ; int n = sc . nextInt ( ) , x = sc . nextInt ( ) , m = sc . nextInt ( ) , mini = x , maxi = x ; while ( m -- > 0 ) { int l = sc . nextInt ( ) , r = sc . nextInt ( ) ; if ( ( l <= maxi ) && ( r >= mini ) ) { maxi = Math . max ( maxi , r ) ; mini = Math . min ( mini , l ) ; } } System . out . println ( maxi - mini + 1 ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (cast_expression type: (integral_type) value: (decimal_floating_point_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (identifier)) declarator: (variable_declarator name: (identifier) value: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)))))))))