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
51
52
53
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define IOS cin.tie(0); ios_base::sync_with_stdio(0)
 
using ll = long long;
using namespace std;

const int N = 3005;

int n, m, q, ans[100005], h[N][N], v[N][N];
char s[N], t[N];
vector<tuple<int, int, int, int>> queries[N];

int main() {
	scanf("%d%d%d%s%s", &n, &m, &q, s + 1, t + 1);
	for (int i = 0; i < q; ++i) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		queries[a].pb({b, c, d, i});
	}
	for (int i = 1; i <= n; ++i) {
		if (queries[i].empty()) continue;
		
		for (int j = 0; j <= m; ++j)
			h[i - 1][j] = v[i - 1][j] = j;
			
		for (int a = i; a <= n; ++a) {
			for (int b = 1; b <= m; ++b) {
				if (s[a] != t[b]) {
					h[a][b] = max(v[a][b - 1], h[a - 1][b]);
					v[a][b] = min(v[a][b - 1], h[a - 1][b]);
				}
				else {
					h[a][b] = v[a][b - 1];
					v[a][b] = h[a - 1][b];
				}
			}
		}
		for (auto [row, a, b, id] : queries[i]) 
			for (int col = a; col <= b; ++col) 
				ans[id] += (h[row][col] < a);
	}
	for (int i = 0; i < q; ++i)
		printf("%d\n", ans[i]);
	return 0;
}