This page is still under construction.

Parts of this page are still being built. What you see may change.

Recipes

Time limit1sMemory limit128 MB

Summary
Multiply each recipe amount by a constant and print the result as a reduced integer or mixed fraction.
Level

Easy2 of 10

Topics
Implementation, Math, Number theory
Solved
No attempts yet

Problem

A little-known fact about Richard Stallman is that he loves to share not only his source code, but also his recipes. Because of this, he often needs to scale a recipe up to feed a few extra programmers: he multiplies the amount of every ingredient by some constant factor. Doing this by hand has grown tedious, and the fractions involved lead to mistakes. Hungry programmers get grumpy when the food turns out badly, and they start losing focus and breaking the build. Your task is to prevent all of that by writing a program that converts recipes automatically.

Input

The first line contains the number KK of data sets. The KK data sets follow, each describing one recipe in the format below.

The first line of a recipe contains two integers II and CC: the number of ingredients and the constant factor to multiply by. The next II lines each describe one ingredient with three integers ww, nn, and dd, giving the amount used in the original recipe.

  • ww is the number of whole units. For flour, w=2w = 2 means 2 cups.
  • nn and dd give the fractional part. For flour, n=1n = 1 and d=4d = 4 means an extra 1/41/4 cup.

On each ingredient line, ww and nn are separated by whitespace, while nn and dd are separated by a single slash (written as n/d). The denominator dd is always one of 11, 22, 33, 44, or 88.

Output

For each data set, print a line Data Set x: on its own, where xx is the data set number, starting from 11. On the following II lines, print the scaled amount of each ingredient.

  • If the result has no fractional part, print it as a single integer.
  • Otherwise, print it in reduced form as whole n/d, with the whole part separated from the fraction by a single space (the whole part may be 00).

Separate consecutive data sets with a blank line.

Examples1

  1. Example 1

    Input
    2
    5 2
    2 3/4
    0 1/8
    3 0/1
    1 1/2
    0 2/3
    4 3
    1 1/4
    2 1/2
    0 1/3
    12 1/2
    
    Expected output
    Data Set 1:
    5 1/2
    0 1/4
    6
    3
    1 1/3
    
    Data Set 2:
    3 3/4
    7 1/2
    1
    37 1/2