#include <iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include <math.h>
#include <set>
#include <map>
using namespace std;
int a[1005]= {0};
int res[1005]= {0};
string ss[1005];
string ss1[1005];
int x,j;
int n,g,f,h;
int main()
{
cin>>n;
getchar();
string s;
for(int i=1; i<=n; i++)
{
getline(cin,s);
// cout<<s;
int c=s.find("km");
//找到km
if(c!=-1)
{
//存储单位
ss[i] = "km";
//存储数字
// cout<<c<<endl;
for(int j=0; j<c-1; j++)
{
char zf = s[j] ;
int b = zf - '0';
// cout<<"b"<<b<<endl;
// cout<<"c-j-1:"<<c-j-1<<endl;
a[i] =a[i]+ b * pow(10, (c-j-2));
}
//要化成什么
c = s.find("mm");
if(c!=-1)
{
ss1[i]="mm";
res[i] = a[i]*1000000;
}
else
{
ss1[i]="m";
res[i] = a[i] *1000;
}
}
else
{
c=s.find("m");
if(c!=-1)
{
//存储单位
ss[i] = "m";
//存储数字
for(int j=0; j<c-1; j++)
{
char zf = s[j] ;
int b = zf - '0';
a[i] =a[i]+ b * pow(10, (c-j-2));
}
ss1[i]="mm";
res[i] = a[i] *1000;
}
}
c=s.find("kg");
// cout<<c<<endl;
//找到km
if(c!=-1)
{
//存储单位
ss[i] = "kg";
a[i] = 0;
//存储数字
for(int j=0; j<c-1; j++)
{
char zf = s[j] ;
int b = zf - '0';
a[i] =a[i]+ b * pow(10, (c-j-2));
}
//要化成什么
c = s.find("mg");
if(c!=-1)
{
ss1[i]="mg";
res[i] = a[i]*1000000;
}
else
{
ss1[i]="g";
res[i] = a[i] *1000;
}
}
else
{
c=s.find("g");
// cout<<"g:"<<c<<endl;
// cout<<c;
if(c!=-1)
{
//存储单位
ss[i] = "g";
a[i] = 0;
//存储数字
for(int j=0; j<c-1; j++)
{
char zf = s[j] ;
int b = zf - '0';
a[i] =a[i]+ b * pow(10, (c-j-2));
// cout<<a[i]<<endl;
}
ss1[i]="mg";
res[i] = a[i] *1000;
}
}
s.clear();
}
for(int i = 1; i<=n; i++)
{
cout<<a[i]<<" "<<ss[i]<<" = "<<res[i]<<" "<<ss1[i]<<endl;
}
return 0;
}