// Arup Guha
// 8/30/2017
// Solution to 2017 UCF Locals Problem: Simplified Keyboard

import java.util.*;

public class typing {

	// Keyboard
	final public static int COL = 9;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=0; loop<numCases; loop++) {
			String s = stdin.next();
			String t = stdin.next();
			System.out.println(solve(s,t));
		}
	}

	public static int solve(String s, String t) {

		// Easy cases.
		if (s.equals(t)) return 1;
		if (s.length() != t.length()) return 3;

		// Go through each letter.
		for (int i=0; i<s.length(); i++) {

			// Get the character codes.
			int a = s.charAt(i) - 'a';
			int b = t.charAt(i) - 'a';

			// If either dx or dy is greater than 1, we fail.
			if (Math.abs(a/COL-b/COL) > 1 || Math.abs(a%COL-b%COL) > 1) return 3;
		}

		// If we get here, we matched all letters "inexactly".
		return 2;
	}
 }