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
#include<bits/stdc++.h>
using namespace std;

string s;
string t;
int dynamik[3010][3010];
int funkcja(int sp, int sk, int tp, int tk)
{
	int i=sp-1, j;
	for(j=tp-1;j<=tk;j++)
		dynamik[i][j] = 0;
	j = tp-1;
	for(i=sp-1;i<=sk;i++)
		dynamik[i][j] = 0;
	for(i=sp;i<=sk;i++)
	{
		for(j=tp;j<=tk;j++)
		{
			dynamik[i][j] = 0;
			if(s[i] == t[j])
				dynamik[i][j] = dynamik[i-1][j-1]+1;
			else
				dynamik[i][j] = max(dynamik[i-1][j], dynamik[i][j-1]);
		}
	}
	return dynamik[sk][tk];
	
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m, q, i, a1, b1, a2, b2;
	cin>>n>>m>>q;
	getline(cin, s);
	getline(cin, s);
	getline(cin, t);
	s = " "+s;
	t = " "+t;
	for(i=0;i<q;i++)
	{
		cin>>a1>>b1>>a2>>b2;
		
		cout<<funkcja(a1,b1,a2,b2)<<"\n";
		
	}
}