#include <bits/stdc++.h>

using namespace std;

int bfs(const string &start, const string &end)
{
    int rowS = start[1] - '1', colS = start[0] - 'a';
    int rowE = end[1] - '1', colE = end[0] - 'a';

    queue<pair<pair<int, int>, int>> q;
    vector<vector<bool>> vis(8, vector<bool>(8, false));

    q.push({{rowS, colS}, 0});
    vis[rowS][colS] = true;

    while (!q.empty())
    {
        auto [pos, cost] = q.front(); q.pop();
        auto [row, col] = pos;

        if (row == rowE && col == colE)
            return cost;

        vector<pair<int, int>> moves = {{-2, -1}, {-2, 1}, {-1, 2}, {1, 2}, {2, 1}, {2, -1}, {-1, -2}, {1, -2}};
        for (const auto [dy, dx] : moves)
        {
            int nextRow = row + dy, nextCol = col + dx;
            if (nextRow < 0 || nextRow > 7 || nextCol < 0 || nextCol > 7) continue;

            if (!vis[nextRow][nextCol])
            {
                q.push({{nextRow, nextCol}, cost + 1});
                vis[nextRow][nextCol] = true;
            }
        }
    }

    return -1;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string start, end;
        cin >> start >> end;
        cout << bfs(start, end) << endl;
    }
    return 0;
}