public static void main ( String args [ ] ) {
  FastReader input = new FastReader ( ) ;
  PrintWriter out = new PrintWriter ( System . out ) ;
  int T = input . nextInt ( ) ;
  while ( T -- > 0 ) {
    long p = input . nextLong ( ) ;
    long q = input . nextLong ( ) ;
    long b = input . nextLong ( ) ;
    q = q / gcd ( p , q ) ;
    long g = gcd ( q , b ) ;
    while ( g > 1 ) {
      while ( q % g == 0 ) {
        q = q / g ;
      }
      g = gcd ( q , b ) ;
    }
    if ( q == 1 ) {
      out . println ( "Finite" ) ;
    }
    else {
      out . println ( "Infinite" ) ;
    }
  }
  out . close ( ) ;
}

public static void main ( String args [ ] ) { FastReader input = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int T = input . nextInt ( ) ; while ( T -- > 0 ) { long p = input . nextLong ( ) ; long q = input . nextLong ( ) ; long b = input . nextLong ( ) ; q = q / gcd ( p , q ) ; long g = gcd ( q , b ) ; while ( g > 1 ) { while ( q % g == 0 ) { q = q / g ; } g = 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)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (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: (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)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (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: (block (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: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))