#include <bits/stdc++.h>
#define int long long
using namespace std;
int a, b, ans;
bool vis[10100][10100];
struct wat
{
int n1, n2, step;
list <int> v;
};
queue <wat> q;
void bfs()
{
wat n;
n.n1 = 0, n.n2 = 0, n.step = 0;
vis[0][0] = 1;
q.push(n);
while(1)
{
wat now = q.front();
q.pop();
if(now.n1 == ans || now.n2 == ans)
{
cout << now.step << " ";
while(!now.v.empty())
{
cout << now.v.front() << " ";
now.v.pop_front();
}
cout << endl;
break;
}
wat nx = now;
nx.step++;
if(now.n1 != 0)
{
nx.n1 = 0;
if(!vis[0][nx.n2])
{
nx.v.push_back(3);
vis[0][nx.n2] = 1;
q.push(nx);
nx.v.pop_back();
}
}
if(now.n2 != 0)
{
nx.n1 = now.n1, nx.n2 = 0;
if(!vis[nx.n1][0])
{
nx.v.push_back(4);
vis[nx.n1][0] = 1;
q.push(nx);
nx.v.pop_back();
}
}
if(now.n1 != a)
{
nx.n1 = a, nx.n2 = now.n2;
if(!vis[a][nx.n2])
{
nx.v.push_back(1);
vis[a][nx.n2] = 1;
q.push(nx);
nx.v.pop_back();
}
}
if(now.n2 != b)
{
nx.n1 = now.n1, nx.n2 = b;
if(!vis[nx.n1][b])
{
nx.v.push_back(2);
vis[nx.n1][b] = 1;
q.push(nx);
nx.v.pop_back();
}
}
if(now.n1 + now.n2 >= a)
{
nx.n1 = a, nx.n2 = now.n1 + now.n2 - a;
}
else
{
nx.n1 = now.n1 + now.n2;
nx.n2 = 0;
}
if(!vis[nx.n1][nx.n2])
{
nx.v.push_back(5);
vis[nx.n1][nx.n2] = 1;
q.push(nx);
nx.v.pop_back();
}
if(now.n1 + now.n2 >= b)
{
nx.n1 = now.n1 + now.n2 - b, nx.n2 = b;
}
else
{
nx.n1 = 0;
nx.n2 = now.n1 + now.n2;
}
if(!vis[nx.n1][nx.n2])
{
nx.v.push_back(6);
vis[nx.n1][nx.n2] = 1;
q.push(nx);
nx.v.pop_back();
}
}
return;
}
signed main()
{
std::ios::sync_with_stdio(0);
int n;
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> a >> b >> ans;
bfs();
}
return 0;
}