#include <iostream>
#include <vector>
using namespace std;
string a, b;
int n, m, Mn, ans;
vector <vector <int>> dp(3e3, vector <int>(3e3, 1e9));
vector <vector <int>> mn(3e3, vector <int>(3e3, 0));
void solve() {
cin >> a >> b;
n = a.size();
m = b.size();
a = "a" + a;
b = "a" + b;
ans = dp[0][0] = n + m + 3;
for (int i = 0; i <= n; i++) mn[i][0] = dp[0][0];
for (int j = 0; j <= m; j++) mn[0][j] = dp[0][0];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
Mn = min(mn[i - 1][j], mn[i][j - 1]);
if (a[i] != b[j]) { mn[i][j] = Mn; continue; }
dp[i][j] = (a[i - 1] == b[j - 1] ? dp[i - 1][j - 1] - 1 : Mn + 2);
if (i == n && j == m) dp[i][j] -= 3;
mn[i][j] = min(Mn, dp[i][j]);
}
}
cout << mn[n][m] << endl;
}
int main()
{
int t;
cin >> t;
for (int i = 0; i < t; i++) solve();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 48ms | 142892 KiB | ||||
2 | Accepted | 61ms | 143232 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 71ms | 143572 KiB | ||||
4 | Wrong answer | 92ms | 143616 KiB | ||||
5 | Wrong answer | 90ms | 143828 KiB | ||||
6 | Wrong answer | 90ms | 144040 KiB | ||||
7 | Wrong answer | 104ms | 144116 KiB | ||||
8 | Wrong answer | 96ms | 144080 KiB | ||||
subtask3 | 11/11 | ||||||
9 | Accepted | 48ms | 144320 KiB | ||||
10 | Accepted | 61ms | 144072 KiB | ||||
11 | Accepted | 61ms | 144332 KiB | ||||
12 | Accepted | 61ms | 144548 KiB | ||||
13 | Accepted | 50ms | 144548 KiB | ||||
14 | Accepted | 48ms | 144672 KiB | ||||
subtask4 | 13/13 | ||||||
15 | Accepted | 61ms | 144744 KiB | ||||
16 | Accepted | 61ms | 144752 KiB | ||||
17 | Accepted | 61ms | 144748 KiB | ||||
18 | Accepted | 50ms | 144848 KiB | ||||
19 | Accepted | 48ms | 144928 KiB | ||||
20 | Accepted | 48ms | 145048 KiB | ||||
subtask5 | 0/24 | ||||||
21 | Accepted | 48ms | 145112 KiB | ||||
22 | Wrong answer | 48ms | 145108 KiB | ||||
23 | Accepted | 61ms | 145112 KiB | ||||
24 | Wrong answer | 50ms | 145120 KiB | ||||
25 | Wrong answer | 48ms | 145124 KiB | ||||
26 | Wrong answer | 48ms | 145120 KiB | ||||
subtask6 | 0/43 | ||||||
27 | Accepted | 72ms | 145456 KiB | ||||
28 | Wrong answer | 97ms | 145252 KiB | ||||
29 | Wrong answer | 97ms | 145272 KiB | ||||
30 | Wrong answer | 105ms | 145252 KiB | ||||
31 | Wrong answer | 79ms | 145244 KiB | ||||
32 | Wrong answer | 92ms | 145252 KiB | ||||
33 | Wrong answer | 107ms | 145512 KiB | ||||
34 | Wrong answer | 101ms | 145464 KiB |