1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 3005, INF = 2e9+6969;

short int dp[nax][nax];
char A[nax],B[nax];
int n,m,q;

void solve(int a, int b, int c, int d)
{
	for(int i=a-1;i<=b;++i) dp[i][c-1] = 0;
	for(int i=c-1;i<=d;++i) dp[a-1][i] = 0;
	for(int i=a;i<=b;++i)
	{
		for(int j=c;j<=d;++j)
		{
			short int tmp = dp[i-1][j-1] + (A[i] == B[j] ? 1 : 0); 
			dp[i][j] = max({dp[i-1][j], dp[i][j-1], tmp});
		}
	}
	printf("%d\n", dp[b][d]);
}

int main()
{
	scanf("%d%d%d", &n, &m, &q);
	scanf("%s", A+1);
	scanf("%s", B+1);
	while(q--)
	{
		int a,b,c,d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		solve(a,b,c,d);
	}
	return 0;
}