public static void main ( String [ ] args ) throws Exception {
  int n = readInt ( ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    long p = readLong ( ) ;
    long q = readLong ( ) ;
    long b = readLong ( ) ;
    q = q / gcd ( q , p ) ;
    long d = gcd ( q , b ) ;
    while ( d > 1 ) {
      q /= d ;
      while ( ( q % d ) == 0 ) {
        q /= d ;
      }
      d = gcd ( q , d ) ;
    }
    output . println ( ( q == 1 ) ? "Finite" : "Infinite" ) ;
  }
  output . flush ( ) ;
  output . close ( ) ;
}

public static void main ( String [ ] args ) throws Exception { int n = readInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { long p = readLong ( ) ; long q = readLong ( ) ; long b = readLong ( ) ; q = q / gcd ( q , p ) ; long d = gcd ( q , b ) ; while ( d > 1 ) { q /= d ; while ( ( q % d ) == 0 ) { q /= d ; } d = gcd ( q , d ) ; } output . println ( ( q == 1 ) ? " Finite " : " Infinite " ) ; } output . flush ( ) ; output . close ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation 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 name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation 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 (expression_statement (assignment_expression left: (identifier) right: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal))) body: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (ternary_expression condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (string_literal) alternative: (string_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))