A. Image

这是一个关于图像处理的问题,给定一个2x2的图像,每个像素可以是26种颜色之一。目标是通过不超过两次操作将所有像素变为同一颜色。每一步可以选择最多两个相同颜色的像素并改变它们的颜色。问题要求找出达成目标所需的最小操作次数。
摘要由CSDN通过智能技术生成

You have an image file of size 2×22×2, consisting of 44 pixels. Each pixel can have one of 2626 different colors, denoted by lowercase Latin letters.

You want to recolor some of the pixels of the image so that all 44 pixels have the same color. In one move, you can choose no more than two pixels of the same color and paint them into some other color (if you choose two pixels, both should be painted into the same color).

What is the minimum number of moves you have to make in order to fulfill your goal?

Input

The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

Each test case consists of two lines. Each of these lines contains two lowercase letters of Latin alphabet without any separators, denoting a row of pixels in the image.

Output

For each test case, print one integer — the minimum number of moves you have to make so that all 44 pixels of the image have the same color.

Example

input

Copy

 

5

rb

br

cc

wb

aa

aa

ab

cd

yy

xx

output

Copy

1
2
0
3
1
#include <bits/stdc++.h>
using namespace std;
int t,cnt;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> t;
    while(t--)
    {
        cnt = 0;
        int flag[4] = {1,1,1,1};
        string a, b;
        cin >> a >> b;
        string s = a + b;
        for(int i = 0; i < 4; i++)
        {
            for(int j = i+1; j < 4; j++)
            {
                if(s[j] == s[i])
                {
                    flag[j] = 0;
                }
            }
        }
        for(int i = 0 ; i < 4; i++)
        {
            cnt += flag[i];
        }
        cout << cnt - 1 << endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值