public static void main ( String args [ ] ) {
  MyScanner sc = new MyScanner ( ) ;
  out = new PrintWriter ( new BufferedOutputStream ( System . out ) , true ) ;
  int n = sc . nextInt ( ) ;
  for ( int z = 1 ;
  z <= n ;
  z ++ ) {
    long p = sc . nextLong ( ) ;
    long q = sc . nextLong ( ) ;
    long b = sc . nextLong ( ) ;
    q = q / gcd ( p , q ) ;
    b = gcd ( b , q ) ;
    while ( b != 1 ) {
      while ( q % b == 0 ) q = q / b ;
      b = gcd ( q , b ) ;
    }
    if ( q == 1 ) out . println ( "Finite" ) ;
    else out . println ( "Infinite" ) ;
  }
  out . close ( ) ;
}

public static void main ( String args [ ] ) { MyScanner sc = new MyScanner ( ) ; out = new PrintWriter ( new BufferedOutputStream ( System . out ) , true ) ; int n = sc . nextInt ( ) ; for ( int z = 1 ; z <= n ; z ++ ) { long p = sc . nextLong ( ) ; long q = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; q = q / gcd ( p , q ) ; b = gcd ( b , q ) ; while ( b != 1 ) { while ( q % b == 0 ) q = q / b ; b = gcd ( q , b ) ; } if ( q == 1 ) out . println ( " Finite " ) ; else out . println ( " Infinite " ) ; } out . close ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))) (true))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (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)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) body: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal)))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))