var log = console.log;
if (typeof process != "undefined") {
    var input = "";
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    process.stdin.on('data', function(chunk) {
        input += chunk;
    });
    process.stdin.on('end', function() {
        var lines = input.split("\n");
        main(lines);
    });
}

//-----

function main(lines) {
	lines.shift();
	while(lines.length > 0){
		var dataset = lines.slice(0,2);
		dataset = dataset.map(function(row){
			return row.split("").filter(function(e){
				var code = e.charCodeAt(0);
				return 97 <= code && code <= 122;
			}).join("");
		});
		processDataset(dataset);
		lines = lines.slice(2);
	}
}

function processDataset(dataset){
	var f = dataset[0];
	var s = dataset[1];
	var str = "";
	while(f.length > 0 && s.length > 0){
		var ft = f.charAt(0);
		var st = s.charAt(0);
		var ft_s = s.indexOf(ft);
		var st_f = f.indexOf(st);
		if(ft_s == -1 && st_f == -1){
			f = f.slice(1);
			s = s.slice(1);
			continue;
		}else if(ft_s == -1){
			f = f.slice(st_f+1);
			s = s.slice(1);
			str += st;
		}else if(st_f == -1){
			f = f.slice(1);
			s = s.slice(ft_s+1);
			str += ft;
		}else{
			if(ft_s <= st_f){
				f = f.slice(1);
				s = s.slice(ft_s+1);
				str += ft;
			}else{
				f = f.slice(st_f+1);
				s = s.slice(1);
				str += st;
			}
		}
	}
	log(str.length);
}