#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

#define brute 2

int T = 10;
int maxval = 0;

int count(int factorial, int P) {
     int power = 0;
     long long iuhu = P;

     while(true) {
          int added = (factorial / iuhu);

          if(added == 0) {
               break;
          }

          power += added;

          iuhu = (long long)iuhu * P;
     }

     return power;
}

int solve(int N, int M, int P) {
     long long iuhu = P;

     int den = N + M - 2;
     int num1 = N - 1;
     int num2 = M - 1;

     int aux = P;
     for(int i=2; i<=P; i++) {
          if(aux == 1) {
               break;
          }

          if(aux % i == 0) {
               int exp = 0;
               while(aux % i == 0) {
                    exp ++;

                    aux /= i;
               }

               int power = count(den, i) - count(num1, i) - count(num2, i);

               if(power < exp) {
                    return 0;
               }
          }
     }

     return 1;
}

int main() {
     srand(time(NULL));

     fstream f2;
     f2.open("grader_test5.in", ios::out);

     f2 << T << '\n';

     while(T--) {
          int N = 2, M = 2, P = 3;

          if(brute == 0) {
               // O(n^2)
               maxval = 400;
          }
          else if(brute == 1) {
               // O(n)
               maxval = 1000000;
          }
          else if(brute == 2) {
               maxval = 1000000000;
          }

          int rez = rand() % 100000;

          if(rez == 1) {
               while(solve(N, M, P) == 0) {
                    N = rand() % (maxval - 3);
                    N += 3;

                    M = rand() % (maxval - 3);
                    M += 3;

                    P = rand() % (maxval - 1);
                    P += 1;
               }
          }
          else {
               N = rand() % (maxval - 3);
               N += 3;

               M = rand() % (maxval - 3);
               M += 3;

               P = rand() % (maxval - 1);
               P += 1;
          }

          f2 << N << ' ' << M << ' ' << P << '\n';
     }


     f2.close();

     return 0;
}
