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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto & i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;
typedef unsigned long long T;

constexpr int N = 48;
constexpr int W = 64;
constexpr T LAST = (1ull<<63);
T set[26][48];
T row[48];
T bot, top, x, y;
char a[3005];
char b[3005];

int calc(int s1, int len1, int s2, int len2){
	memset(set, 0, sizeof(set));
	memset(row, 0, sizeof(row));
	FOR(i, len1) set[a[s1+i]-'a'][i>>6] |= (1ull<<(i & (W-1)));

	int nn = (std::max(len1, len2)>>6)+1;
	assert(nn <= N);

	FOR(ch, len2){
		bot = 1;
		auto& ss = set[b[s2+ch]-'a'];
		FOR(j, nn){
			y = row[j];
			x = y | ss[j];
			top = y >> (W-1);
			y = ((y << 1) | bot);
			if(x < y) top = 1;
			row[j] = x & ((x - y) ^ x);
			bot = top;
		}
	}

	int ans = 0;
	FOR(i, nn) ans += __builtin_popcountll(row[i]);
	return ans;
}

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);

	int n, m, q;
	std::cin >> n >> m >> q;
	FOR(i, n) std::cin >> a[i];
	FOR(i, m) std::cin >> b[i];
	FOR(_, q){
		int i, j, k, l;
		std::cin >> i >> j >> k >> l;
		i--;j--;k--;l--;
		std::cout << calc(i, j-i+1, k, l-k+1) << "\n";
	}

	return 0;
}