#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
int a;
string b, c, d, e;
int l = 1000;
cin >> a >> b >> c >> d >> e;
if (b == "km" && e == "mm" || b == "kg" && e == "mg")
l = 1000000;
cout << a << " " << b << " " << c << " " << a * l << " " << e << endl;
}
return 0;
}