#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;

bool G[10][10];

vector <int> solve( int a, int b )
{
    queue < vector <int> > Q;
    vector <int> S;
    S.push_back( a );
    Q.push( S );
    
    while ( Q.empty() == false )
    {
        vector <int> C = Q.front();
        Q.pop();
        int cur = *( C.end()-1 );

        if ( cur == b )
        {
            return C;
        }

        for ( int i = 0; i < 10; i++ )
        {
            if ( G[cur][i] && find( C.begin(), C.end(), i ) == C.end() )
            {
                C.push_back( i );
                Q.push( C );
                C.pop_back();
            }
        }
    }

    return vector <int>();
}

int main( void )
{
    memset( G, false, sizeof( G ) );
    G[0][1] = G[1][0] = true;
    G[1][2] = G[2][1] = true;
    G[2][3] = G[3][2] = true;
    G[3][4] = G[4][3] = true;
    G[4][5] = G[5][4] = true;
    G[5][6] = true;
    G[6][7] = true;
    G[7][8] = true;
    G[8][9] = true;
    G[9][5] = true;

    int n;
    cin >> n;

    for ( int i = 0; i < n; i++ )
    {
        int a, b;
        cin >> a >> b;
        vector <int> path = solve( a, b );
        cout << path.size() << endl;
        for ( vector <int> ::iterator it = path.begin(); it != path.end(); it++ )
        {
            cout << *it;
            if ( ( it + 1 ) != path.end() ) cout << " ";
            else cout << endl;
        }
    }

    return 0;
}