#include<stdio.h>

int gcd(int a, int b);  /* Return gcd(a,b) */

int compare(int a, int b, int x, int y);  /* Compare fractions a/b and x/y.  
                                             Return -1 if a/b < x/y,
 					             0 if a/b == x/y,
					             1 if a/b > x/y
					  */

int main(){

  int i, j, k;
  int len, n, d;
  int result;
  int lowern, lowerd, uppern, upperd;

  /* Read length of input sequence */
  scanf("%d",&len);


  
  /* For each input fraction */
  for (k = 0; k < len; k++){
    scanf("%d %d",&n,&d);


    /* Set bracketing pair to 1/99 and 98/99 */

    lowern = 1;
    lowerd = 99;
    uppern = 98;
    upperd = 99;

    /* Generate all proper fractions 0 < n/d < 1 with 0 < d <= 99 and
       retain if it is better than one of the current bracketing
       pair */ 

    for (j = 1; j < 100; j++){
      for (i = 1; i < j; i++){
	if (gcd(i,j) == 1){
	  result = compare(n,d,i,j);

	  if (result < 0){  // New fraction lies above n/d
	    result = compare(i,j,uppern,upperd);
	    if (result < 0){  //  If i/j < uppern/upperd
	      uppern = i;     //     update uppern/upperd = i/j
	      upperd = j;
	    }
	  }else{
	    if (result > 0){ // New fraction lies below n/d
	      result = compare(lowern,lowerd,i,j);
	      if (result < 0){  //  If i/j > lowern/lowerd 
		lowern = i;     //     update lowern/lowerd = i/j
		lowerd = j;
	      }
	    }
	  }
	}
      }
    }

    /* Print output */

    printf("%d %d %d %d\n",lowern,lowerd,uppern,upperd);

  }

}

/* Auxiliary functions defined below */

/* gcd */

int gcd(int a, int b){
  if (a == b){
    return a;
  }

  if (a < b){
    return gcd(a,b-a);
  }else{
    return gcd(b,a-b);
  }
}

/* comparing two fractions */

int compare(int a, int b, int x, int y){
  if (a*y == b*x) { return 0; }
  if (a*y < b*x) {return -1; }
  return 1;
}


