///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef double ld;

ld PI = acos(-1);

struct base {
	ld a, b;
	base(ld _a = 0.0, ld _b = 0.0) : a(_a), b(_b) {}
	const base operator + (const base &c) const
		{ return base(a + c.a, b + c.b); }
	const base operator - (const base &c) const
		{ return base(a - c.a, b - c.b); }
	const base operator * (const base &c) const
		{ return base(a * c.a - b * c.b, a * c.b + b * c.a); }
};

const int N = 1 << 18;
base w_pre[N|1], w[N|1]; int rev[N];

void calcw() {
	for(int i = 0; i <= N; ++i)
		w_pre[i] = base(cos(2*PI/N*i), sin(2*PI/N*i));
}
void calcrev(int n) {
	int sz = 31 - __builtin_clz(n); sz = abs(sz);
	for(int i = 1; i < n - 1; ++i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << sz - 1);
}
void fft(base *p, int n, int dir = 0) {
	for(int i = 1; i < n - 1; i++)
		if(i < rev[i]) swap(p[i], p[rev[i]]);
	for(int h = 1; h < n; h <<= 1) { int l = h << 1;
		if(!dir) for(int j = 0; j < h; ++j) w[j] = w_pre[N/l*j];
		else for(int j = 0; j < h; ++j) w[j] = w_pre[N-N/l*j];
		for(int j = 0 ; j < n; j += l) {
			base t, *wn = w;
			base *u = p + j, *v = u + h, *e = v;
			while(u != e) {
				t = *v * *wn;
				*v = *u - t;
				*u = *u + t;
				++u, ++v, ++wn;
			}
		}
	} if(dir) for(int i = 0; i < n; ++i) p[i].a /= n;
}

const int M = 200010;
const int K = 450;

char a[M], b[M];
base A[N], B[N];
short p[K][M];

int main(int argc, char const *argv[]) {
	scanf("%s", a); scanf("%s", b);
	int n = strlen(a), m = strlen(b), t = n + m - 1, sz = 1;
	while(sz < t) sz <<= 1;

	calcw(); calcrev(sz);

	for(int i = 0; i < m; i++) B[i] = base(b[i] == '0' ? -1 : 1, 0);
	fft(B, sz);

	for(int blc = 0; blc * K < n; blc++) {
		int l = blc * K, r = (blc + 1) * K;
		if(r > n) break;
		for(int i = l; i < r; i++)
			A[i - l] = base(a[r - i + l - 1] == '0' ? -1 : 1, 0);
		for(int i = K; i < sz; i++)
			A[i] = base(0, 0);

		fft(A, sz);
		for(int i = 0; i < sz; i++)
			A[i] = A[i] * B[i];
		fft(A, sz, 1);

		for(int i = 0; i <= m - K; i++) {
			double y = A[i + K - 1].a;
			int x = y >= 0 ? y + 0.5 : y - 0.5;
			p[blc][i] = (K - x) >> 1;
		}
	}

	int Q; scanf("%d", &Q); while(Q--){
		int pa, pb, l; scanf("%d %d %d", &pa, &pb, &l);
		int l1 = pa, r1 = pa + l - 1;
		int l2 = pb, r2 = pb + l - 1;

		int ans = 0;
		int L = l1 / K, R = r1 / K;

		if(L == R) {
			for(int i = l1; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		} else {
			for(int i = l1; i < (L + 1) * K; i++)
				ans += a[i] != b[i - l1 + l2];
			for(int b = L + 1; b < R; b++)
				ans += p[b][b * K - l1 + l2];
			for(int i = R * K; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		}
		printf("%d\n", ans);
	}
}


///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef double ld;

ld PI = acos(-1);

struct base {
	ld a, b;
	base(ld _a = 0.0, ld _b = 0.0) : a(_a), b(_b) {}
	const base operator + (const base &c) const
		{ return base(a + c.a, b + c.b); }
	const base operator - (const base &c) const
		{ return base(a - c.a, b - c.b); }
	const base operator * (const base &c) const
		{ return base(a * c.a - b * c.b, a * c.b + b * c.a); }
};

const int N = 1 << 18;
base w_pre[N|1], w[N|1]; int rev[N];

void calcw() {
	for(int i = 0; i <= N; ++i)
		w_pre[i] = base(cos(2*PI/N*i), sin(2*PI/N*i));
}
void calcrev(int n) {
	int sz = 31 - __builtin_clz(n); sz = abs(sz);
	for(int i = 1; i < n - 1; ++i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << sz - 1);
}
void fft(base *p, int n, int dir = 0) {
	for(int i = 1; i < n - 1; i++)
		if(i < rev[i]) swap(p[i], p[rev[i]]);
	for(int h = 1; h < n; h <<= 1) { int l = h << 1;
		if(!dir) for(int j = 0; j < h; ++j) w[j] = w_pre[N/l*j];
		else for(int j = 0; j < h; ++j) w[j] = w_pre[N-N/l*j];
		for(int j = 0 ; j < n; j += l) {
			base t, *wn = w;
			base *u = p + j, *v = u + h, *e = v;
			while(u != e) {
				t = *v * *wn;
				*v = *u - t;
				*u = *u + t;
				++u, ++v, ++wn;
			}
		}
	} if(dir) for(int i = 0; i < n; ++i) p[i].a /= n;
}

const int M = 200010;
const int K = 1500;

char a[M], b[M];
base A[N], B[N];
short p[K][M];

int main(int argc, char const *argv[]) {
	scanf("%s", a); scanf("%s", b);
	int n = strlen(a), m = strlen(b), t = n + K - 1, sz = 1;
	while(sz < t) sz <<= 1;

	calcw(); calcrev(sz);

	for(int i = 0; i < m; i++) B[i] = base(b[i] == '0' ? -1 : 1, 0);
	fft(B, sz);

	for(int blc = 0; blc * K < n; blc++) {
		int l = blc * K, r = (blc + 1) * K;
		if(r > n) break;
		for(int i = l; i < r; i++)
			A[i - l] = base(a[r - i + l - 1] == '0' ? -1 : 1, 0);
		for(int i = K; i < sz; i++)
			A[i] = base(0, 0);

		fft(A, sz);
		for(int i = 0; i < sz; i++)
			A[i] = A[i] * B[i];
		fft(A, sz, 1);

		for(int i = 0; i <= m - K; i++) {
			double y = A[i + K - 1].a;
			int x = y >= 0 ? y + 0.5 : y - 0.5;
			p[blc][i] = (K - x) >> 1;
		}
	}

	int Q; scanf("%d", &Q); while(Q--){
		int pa, pb, l; scanf("%d %d %d", &pa, &pb, &l);
		int l1 = pa, r1 = pa + l - 1;
		int l2 = pb, r2 = pb + l - 1;

		int ans = 0;
		int L = l1 / K, R = r1 / K;

		if(L == R) {
			for(int i = l1; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		} else {
			for(int i = l1; i < (L + 1) * K; i++)
				ans += a[i] != b[i - l1 + l2];
			for(int b = L + 1; b < R; b++)
				ans += p[b][b * K - l1 + l2];
			for(int i = R * K; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		}
		printf("%d\n", ans);
	}
}


///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

typedef long long ll;
typedef pair<int, int> ii;
typedef double ld;

ld PI = acos(-1);

struct base {
	ld a, b;
	base(ld _a = 0.0, ld _b = 0.0) : a(_a), b(_b) {}
	const base operator + (const base &c) const
		{ return base(a + c.a, b + c.b); }
	const base operator - (const base &c) const
		{ return base(a - c.a, b - c.b); }
	const base operator * (const base &c) const
		{ return base(a * c.a - b * c.b, a * c.b + b * c.a); }
};

const int N = 1 << 18;
base w_pre[N|1], w[N|1]; int rev[N];

void calcw() {
	for(int i = 0; i <= N; ++i)
		w_pre[i] = base(cos(2*PI/N*i), sin(2*PI/N*i));
}
void calcrev(int n) {
	int sz = 31 - __builtin_clz(n); sz = abs(sz);
	for(int i = 1; i < n - 1; ++i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << sz - 1);
}
void fft(base *p, int n, int dir = 0) {
	for(int i = 1; i < n - 1; i++)
		if(i < rev[i]) swap(p[i], p[rev[i]]);
	for(int h = 1; h < n; h <<= 1) { int l = h << 1;
		if(!dir) for(int j = 0; j < h; ++j) w[j] = w_pre[N/l*j];
		else for(int j = 0; j < h; ++j) w[j] = w_pre[N-N/l*j];
		for(int j = 0 ; j < n; j += l) {
			base t, *wn = w;
			base *u = p + j, *v = u + h, *e = v;
			while(u != e) {
				t = *v * *wn;
				*v = *u - t;
				*u = *u + t;
				++u, ++v, ++wn;
			}
		}
	} if(dir) for(int i = 0; i < n; ++i) p[i].a /= n;
}

const int M = 200010;
const int K = 3600;

char a[M], b[M];
base A[N], B[N];
short p[60][M];

int main(int argc, char const *argv[]) {
	scanf("%s", a); scanf("%s", b);
	int n = strlen(a), m = strlen(b), t = m + K - 1, sz = 1;
	while(sz < t) sz <<= 1;

	calcw(); calcrev(sz);

	for(int i = 0; i < m; i++) B[i] = base(b[i] == '0' ? -1 : 1, 0);
	fft(B, sz);

	for(int blc = 0; blc * K < n; blc++) {
		int l = blc * K, r = (blc + 1) * K;
		if(r > n) break;
		for(int i = l; i < r; i++)
			A[i - l] = base(a[r - i + l - 1] == '0' ? -1 : 1, 0);
		for(int i = K; i < sz; i++)
			A[i] = base(0, 0);

		fft(A, sz);
		for(int i = 0; i < sz; i++)
			A[i] = A[i] * B[i];
		fft(A, sz, 1);

		for(int i = 0; i <= m - K; i++)
			p[blc][i] = (K - (int)round(A[i + K - 1].a)) >> 1;
	}

	int Q; scanf("%d", &Q); while(Q--){
		int pa, pb, l; scanf("%d %d %d", &pa, &pb, &l);
		int l1 = pa, r1 = pa + l - 1;
		int l2 = pb, r2 = pb + l - 1;

		int ans = 0;
		int L = l1 / K, R = r1 / K;

		if(L == R) {
			for(int i = l1; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		} else {
			for(int i = l1; i < (L + 1) * K; i++)
				ans += a[i] != b[i - l1 + l2];
			for(int b = L + 1; b < R; b++)
				ans += p[b][b * K - l1 + l2];
			for(int i = R * K; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		}
		printf("%d\n", ans);
	}
}


///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef double ld;

ld PI = acos(-1);

struct base {
	ld a, b;
	base(ld _a = 0.0, ld _b = 0.0) : a(_a), b(_b) {}
	const base operator + (const base &c) const
		{ return base(a + c.a, b + c.b); }
	const base operator - (const base &c) const
		{ return base(a - c.a, b - c.b); }
	const base operator * (const base &c) const
		{ return base(a * c.a - b * c.b, a * c.b + b * c.a); }
};

const int N = 1 << 18;
base w_pre[N|1], w[N|1]; int rev[N];

void calcw() {
	for(int i = 0; i <= N; ++i)
		w_pre[i] = base(cos(2*PI/N*i), sin(2*PI/N*i));
}
void calcrev(int n) {
	int sz = 31 - __builtin_clz(n); sz = abs(sz);
	for(int i = 1; i < n - 1; ++i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << sz - 1);
}
void fft(base *p, int n, int dir = 0) {
	for(int i = 1; i < n - 1; i++)
		if(i < rev[i]) swap(p[i], p[rev[i]]);
	for(int h = 1; h < n; h <<= 1) { int l = h << 1;
		if(!dir) for(int j = 0; j < h; ++j) w[j] = w_pre[N/l*j];
		else for(int j = 0; j < h; ++j) w[j] = w_pre[N-N/l*j];
		for(int j = 0 ; j < n; j += l) {
			base t, *wn = w;
			base *u = p + j, *v = u + h, *e = v;
			while(u != e) {
				t = *v * *wn;
				*v = *u - t;
				*u = *u + t;
				++u, ++v, ++wn;
			}
		}
	} if(dir) for(int i = 0; i < n; ++i) p[i].a /= n;
}

const int M = 200010;
const int K = 1000;

char a[M], b[M];
base A[N], B[N];
short p[K][M];

int main(int argc, char const *argv[]) {
	scanf("%s", a); scanf("%s", b);
	int n = strlen(a), m = strlen(b), t = n + K - 1, sz = 1;
	while(sz < t) sz <<= 1;

	calcw(); calcrev(sz);

	for(int i = 0; i < m; i++) B[i] = base(b[i] == '0' ? -1 : 1, 0);
	fft(B, sz);

	for(int blc = 0; blc * K < n; blc++) {
		int l = blc * K, r = (blc + 1) * K;
		if(r > n) break;
		for(int i = l; i < r; i++)
			A[i - l] = base(a[r - i + l - 1] == '0' ? -1 : 1, 0);
		for(int i = K; i < sz; i++)
			A[i] = base(0, 0);

		fft(A, sz);
		for(int i = 0; i < sz; i++)
			A[i] = A[i] * B[i];
		fft(A, sz, 1);

		for(int i = 0; i <= m - K; i++) {
			double y = A[i + K - 1].a;
			int x = y >= 0 ? y + 0.5 : y - 0.5;
			p[blc][i] = (K - x) >> 1;
		}
	}

	int Q; scanf("%d", &Q); while(Q--){
		int pa, pb, l; scanf("%d %d %d", &pa, &pb, &l);
		int l1 = pa, r1 = pa + l - 1;
		int l2 = pb, r2 = pb + l - 1;

		int ans = 0;
		int L = l1 / K, R = r1 / K;

		if(L == R) {
			for(int i = l1; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		} else {
			for(int i = l1; i < (L + 1) * K; i++)
				ans += a[i] != b[i - l1 + l2];
			for(int b = L + 1; b < R; b++)
				ans += p[b][b * K - l1 + l2];
			for(int i = R * K; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		}
		printf("%d\n", ans);
	}
}


///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef double ld;

ld PI = acos(-1);

struct base {
	ld a, b;
	base(ld _a = 0.0, ld _b = 0.0) : a(_a), b(_b) {}
	const base operator + (const base &c) const
		{ return base(a + c.a, b + c.b); }
	const base operator - (const base &c) const
		{ return base(a - c.a, b - c.b); }
	const base operator * (const base &c) const
		{ return base(a * c.a - b * c.b, a * c.b + b * c.a); }
};

const int N = 1 << 18;
base w_pre[N|1], w[N|1]; int rev[N];

void calcw() {
	for(int i = 0; i <= N; ++i)
		w_pre[i] = base(cos(2*PI/N*i), sin(2*PI/N*i));
}
void calcrev(int n) {
	int sz = 31 - __builtin_clz(n); sz = abs(sz);
	for(int i = 1; i < n - 1; ++i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << sz - 1);
}
void fft(base *p, int n, int dir = 0) {
	for(int i = 1; i < n - 1; i++)
		if(i < rev[i]) swap(p[i], p[rev[i]]);
	for(int h = 1; h < n; h <<= 1) { int l = h << 1;
		if(!dir) for(int j = 0; j < h; ++j) w[j] = w_pre[N/l*j];
		else for(int j = 0; j < h; ++j) w[j] = w_pre[N-N/l*j];
		for(int j = 0 ; j < n; j += l) {
			base t, *wn = w;
			base *u = p + j, *v = u + h, *e = v;
			while(u != e) {
				t = *v * *wn;
				*v = *u - t;
				*u = *u + t;
				++u, ++v, ++wn;
			}
		}
	} if(dir) for(int i = 0; i < n; ++i) p[i].a /= n;
}

const int M = 200010;
const int K = 5000;

char a[M], b[M];
base A[N], B[N];
short p[50][M];

int main(int argc, char const *argv[]) {
	scanf("%s", a); scanf("%s", b);
	int n = strlen(a), m = strlen(b), t = m + K - 1, sz = 1;
	while(sz < t) sz <<= 1;

	calcw(); calcrev(sz);

	for(int i = 0; i < m; i++) B[i] = base(b[i] == '0' ? -1 : 1, 0);
	fft(B, sz);

	for(int blc = 0; blc * K < n; blc++) {
		int l = blc * K, r = (blc + 1) * K;
		if(r > n) break;
		for(int i = l; i < r; i++)
			A[i - l] = base(a[r - i + l - 1] == '0' ? -1 : 1, 0);
		for(int i = K; i < sz; i++)
			A[i] = base(0, 0);

		fft(A, sz);
		for(int i = 0; i < sz; i++)
			A[i] = A[i] * B[i];
		fft(A, sz, 1);

		for(int i = 0; i <= m - K; i++)
			p[blc][i] = (K - (int)round(A[i + K - 1].a)) >> 1;
	}

	int Q; scanf("%d", &Q); while(Q--){
		int pa, pb, l; scanf("%d %d %d", &pa, &pb, &l);
		int l1 = pa, r1 = pa + l - 1;
		int l2 = pb, r2 = pb + l - 1;

		int ans = 0;
		int L = l1 / K, R = r1 / K;

		if(L == R) {
			for(int i = l1; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		} else {
			for(int i = l1; i < (L + 1) * K; i++)
				ans += a[i] != b[i - l1 + l2];
			for(int b = L + 1; b < R; b++)
				ans += p[b][b * K - l1 + l2];
			for(int i = R * K; i <= r1; i++)
				ans += a[i] != b[i - l1 + l2];
		}
		printf("%d\n", ans);
	}
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int block128 = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[4] = {0, 0, 0, 0};
	for (int i = 0; i < block128; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X, 3));
	}
	int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int i;
	for (i = block128 * 128; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int block128 = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[2] = {0, 0};
	for (int i = 0; i < block128; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += _mm_popcnt_u64(_mm_extract_epi64(X, 0));
		sum[1] += _mm_popcnt_u64(_mm_extract_epi64(X, 1));
		/*
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X, 3));
		*/
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1];
	int i;
	for (i = block128 * 128; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
#include <smmintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 256;
	int blocks256 = len / 256;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	for (int i = 0; i < blocks256; i++, ptr_a += 2, ptr_b += 2)
	{
		Vec X1 = _mm_load_si128(ptr_a);
		Vec X2 = _mm_load_si128(ptr_a + 1);
		Vec Y1 = _mm_load_si128(ptr_b);
		Vec Y2 = _mm_load_si128(ptr_b + 1);
		X1 = _mm_xor_si128(X1, Y1);
		X2 = _mm_xor_si128(X2, Y2);
		sum[0] += __builtin_popcount(_mm_extract_epi32(X1, 0));
		sum[1] += __builtin_popcount(_mm_extract_epi32(X1, 1));
		sum[2] += __builtin_popcount(_mm_extract_epi32(X1, 2));
		sum[3] += __builtin_popcount(_mm_extract_epi32(X1, 3));
		sum[4] += __builtin_popcount(_mm_extract_epi32(X2, 0));
		sum[5] += __builtin_popcount(_mm_extract_epi32(X2, 1));
		sum[6] += __builtin_popcount(_mm_extract_epi32(X2, 2));
		sum[7] += __builtin_popcount(_mm_extract_epi32(X2, 3));
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1] + sum[2] + sum[3] +
			sum[4] + sum[5] + sum[6] + sum[7];
	int i;
	for (i = blocks256 * 256; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int blocks = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[4] = {0, 0, 0, 0};
	for (int i = 0; i < blocks; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X, 3));
	}
	int ans = sum[0] + sum[1] + sum[2] + sum[3];
	for (int i = blocks * 128; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int block128 = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[4] = {0, 0, 0, 0};
	for (int i = 0; i < block128; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += popcnt(_mm_extract_epi32(X, 0));
		sum[1] += popcnt(_mm_extract_epi32(X, 1));
		sum[2] += popcnt(_mm_extract_epi32(X, 2));
		sum[3] += popcnt(_mm_extract_epi32(X, 3));
	}
	int ans = sum[0] + sum[1] + sum[2] + sum[3];
	for (int i = block128 * 128; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
#include <smmintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 256;
	int blocks256 = len / 256;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	for (int i = 0; i < blocks256; i++, ptr_a += 2, ptr_b += 2)
	{
		Vec X1 = _mm_load_si128(ptr_a);
		Vec X2 = _mm_load_si128(ptr_a + 1);
		Vec Y1 = _mm_load_si128(ptr_b);
		Vec Y2 = _mm_load_si128(ptr_b + 1);
		X1 = _mm_xor_si128(X1, Y1);
		X2 = _mm_xor_si128(X2, Y2);
		sum[0] += __builtin_popcount(_mm_extract_epi32(X1, 0));
		sum[1] += __builtin_popcount(_mm_extract_epi32(X1, 1));
		sum[2] += __builtin_popcount(_mm_extract_epi32(X1, 2));
		sum[3] += __builtin_popcount(_mm_extract_epi32(X1, 3));
		sum[4] += __builtin_popcount(_mm_extract_epi32(X2, 0));
		sum[5] += __builtin_popcount(_mm_extract_epi32(X2, 1));
		sum[6] += __builtin_popcount(_mm_extract_epi32(X2, 2));
		sum[7] += __builtin_popcount(_mm_extract_epi32(X2, 3));
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1] + sum[2] + sum[3] +
			sum[4] + sum[5] + sum[6] + sum[7];
	int i;
	for (i = blocks256 * 256; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	gets(str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d\n", &q);
	for (int i = 0; i < q; i++)
	{
		int p1 = -1, p2 = -1, len = -1;
		gets(str);
		int ptr = 0;
		int strLen = strlen(str);
		int value = 0;
		str[strLen] = ' ';
		str[strLen + 1] = 0;
		strLen++;
		while (ptr < strLen)
		{
			if (str[ptr] == ' ')
			{
				if (p1 == -1)
					p1 = value;
				else if (p2 == -1)
					p2 = value;
				else
					len = value;
				value = 0;
			}
			else
				value = value * 10 + (str[ptr] - '0');
			ptr++;
		}
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
#include <smmintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 256;
	int blocks256 = len / 256;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	for (int i = 0; i < blocks256; i++, ptr_a += 2, ptr_b += 2)
	{
		Vec X1 = _mm_load_si128(ptr_a);
		Vec X2 = _mm_load_si128(ptr_a + 1);
		Vec Y1 = _mm_load_si128(ptr_b);
		Vec Y2 = _mm_load_si128(ptr_b + 1);
		X1 = _mm_xor_si128(X1, Y1);
		X2 = _mm_xor_si128(X2, Y2);
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X1, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X1, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X1, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X1, 3));
		sum[4] += mm_popcnt_u32(_mm_extract_epi32(X2, 0));
		sum[5] += mm_popcnt_u32(_mm_extract_epi32(X2, 1));
		sum[6] += mm_popcnt_u32(_mm_extract_epi32(X2, 2));
		sum[7] += mm_popcnt_u32(_mm_extract_epi32(X2, 3));
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1] + sum[2] + sum[3] +
			sum[4] + sum[5] + sum[6] + sum[7];
	int i;
	for (i = blocks256 * 256; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	gets(str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d\n", &q);
	for (int i = 0; i < q; i++)
	{
		int p1 = -1, p2 = -1, len = -1;
		gets(str);
		int ptr = 0;
		int strLen = strlen(str);
		int value = 0;
		str[strLen] = ' ';
		str[strLen + 1] = 0;
		strLen++;
		while (ptr < strLen)
		{
			if (str[ptr] == ' ')
			{
				if (p1 == -1)
					p1 = value;
				else if (p2 == -1)
					p2 = value;
				else
					len = value;
				value = 0;
			}
			else
				value = value * 10 + (str[ptr] - '0');
			ptr++;
		}
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
#include <nmmintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int block128 = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[2] = {0, 0};
	for (int i = 0; i < block128; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += _mm_popcnt_u64(_mm_extract_epi64(X, 0));
		sum[1] += _mm_popcnt_u64(_mm_extract_epi64(X, 1));
		/*
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X, 3));
		*/
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1];
	int i;
	for (i = block128 * 128; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
#include <smmintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int block128 = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[2] = {0, 0};
	for (int i = 0; i < block128; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += _mm_popcnt_u64(_mm_extract_epi64(X, 0));
		sum[1] += _mm_popcnt_u64(_mm_extract_epi64(X, 1));
		/*
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X, 3));
		*/
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1];
	int i;
	for (i = block128 * 128; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
#include <smmintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 256;
	int blocks256 = len / 256;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	for (int i = 0; i < blocks256; i++, ptr_a += 2, ptr_b += 2)
	{
		Vec X1 = _mm_load_si128(ptr_a);
		Vec X2 = _mm_load_si128(ptr_a + 1);
		Vec Y1 = _mm_load_si128(ptr_b);
		Vec Y2 = _mm_load_si128(ptr_b + 1);
		X1 = _mm_xor_si128(X1, Y1);
		X2 = _mm_xor_si128(X2, Y2);
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X1, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X1, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X1, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X1, 3));
		sum[4] += mm_popcnt_u32(_mm_extract_epi32(X2, 0));
		sum[5] += mm_popcnt_u32(_mm_extract_epi32(X2, 1));
		sum[6] += mm_popcnt_u32(_mm_extract_epi32(X2, 2));
		sum[7] += mm_popcnt_u32(_mm_extract_epi32(X2, 3));
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1] + sum[2] + sum[3] +
			sum[4] + sum[5] + sum[6] + sum[7];
	int i;
	for (i = blocks256 * 256; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int block128 = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[4] = {0, 0, 0, 0};
	for (int i = 0; i < block128; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += popcnt(_mm_extract_epi32(X, 0));
		sum[1] += popcnt(_mm_extract_epi32(X, 1));
		sum[2] += popcnt(_mm_extract_epi32(X, 2));
		sum[3] += popcnt(_mm_extract_epi32(X, 3));
	}
	int ans = sum[0] + sum[1] + sum[2] + sum[3];
	for (int i = blocks * 128; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int blocks = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[4] = {0, 0, 0, 0};
	for (int i = 0; i < blocks; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X, 3));
	}
	int ans = sum[0] + sum[1] + sum[2] + sum[3];
	for (int i = blocks * 128; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
#include <smmintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 256;
	int blocks256 = len / 256;
	int sum[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	for (int i = 0; i < blocks256; i++)
	{
		sum[0] += mm_popcnt_u32(a.a[pa + i] ^ b.a[pb + i]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 1] ^ b.a[pb + i + 1]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 2] ^ b.a[pb + i + 2]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 3] ^ b.a[pb + i + 3]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 4] ^ b.a[pb + i + 4]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 5] ^ b.a[pb + i + 5]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 6] ^ b.a[pb + i + 6]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 7] ^ b.a[pb + i + 7]);
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1] + sum[2] + sum[3] +
			sum[4] + sum[5] + sum[6] + sum[7];
	int i;
	for (i = 0; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int blocks = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[4] = {0, 0, 0, 0};
	for (int i = 0; i < blocks; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X, 3));
	}
	int ans = sum[0] + sum[1] + sum[2] + sum[3];
	for (int i = blocks * 128; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int block128 = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[4] = {0, 0, 0, 0};
	for (int i = 0; i < block128; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += mm_popcnt_u32(_mm_extract_epi32(X, 0));
		sum[1] += mm_popcnt_u32(_mm_extract_epi32(X, 1));
		sum[2] += mm_popcnt_u32(_mm_extract_epi32(X, 2));
		sum[3] += mm_popcnt_u32(_mm_extract_epi32(X, 3));
	}
	int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int i;
	for (i = block128 * 128; i + 32 <= len; i += 32)
		ans += _mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
#include <smmintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

const int BITS = 16;
const int SIZE = (1 << BITS);
const int MASK = SIZE - 1;
int cnt[SIZE];

static inline int32_t __attribute__((always_inline))
mm_popcnt_u32(uint32_t x){
	int32_t result;
	__asm__("popcnt %1, %0" : "=r" (result) : "r" (x));
	return result;
}

static inline int __attribute__((always_inline))
popcnt(uint x)
{
	return cnt[x & MASK] + cnt[x >> BITS];
}

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 256;
	int blocks256 = len / 256;
	int sum[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	for (int i = 0; i < 8 * blocks256; i += 8)
	{
		sum[0] += mm_popcnt_u32(a.a[pa + i] ^ b.a[pb + i]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 1] ^ b.a[pb + i + 1]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 2] ^ b.a[pb + i + 2]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 3] ^ b.a[pb + i + 3]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 4] ^ b.a[pb + i + 4]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 5] ^ b.a[pb + i + 5]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 6] ^ b.a[pb + i + 6]);
		sum[0] += mm_popcnt_u32(a.a[pa + i + 7] ^ b.a[pb + i + 7]);
	}
	//int ans = sum[0] + sum[1] + sum[2] + sum[3];
	int ans = sum[0] + sum[1] + sum[2] + sum[3] +
			sum[4] + sum[5] + sum[6] + sum[7];
	int i;
	for (i = 0; i + 32 <= len; i += 32)
		ans += mm_popcnt_u32(a.a[(pa + i) / 32] ^ b.a[(pb + i) / 32]);
	for (; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	for (int i = 1; i < SIZE; i++)
	{
		cnt[i] = cnt[i & (i - 1)] + 1;
	}
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


//http://codeforces.com/problemset/problem/472/G

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <immintrin.h>
using namespace std;

#ifdef _MSC_VER
	#define ALIGN(x) __declspec(align(x))
	#define ATTR
#else
	#define ALIGN(x) __attribute((aligned(x)))
	#define ATTR __attribute__((target("avx")))
#endif

const int SHIFTS = 128;
const int N = (int)2e5 + 10;
const int T = (N / SHIFTS + 1) * SHIFTS;

typedef unsigned int uint;
typedef __m128i Vec;

struct BitSet
{
	ALIGN(16) uint a[T];
	BitSet()
	{
		memset(a, 0, sizeof(a));
	}
	void set(int pos)
	{
		a[pos >> 5] |= ((uint)1 << (uint)(pos & 31));
	}
	int get(int pos)
	{
		return (a[pos >> 5] >> (uint)(pos & 31)) & 1;
	}
};

BitSet A[SHIFTS];
BitSet B[SHIFTS];

ATTR int getDistance(BitSet &a, BitSet &b, int pa, int pb, int len)
{
	int rem = len % 128;
	int blocks = len / 128;
	const Vec *ptr_a = (const Vec*)(a.a + pa / 32);
	const Vec *ptr_b = (const Vec*)(b.a + pb / 32);
	int sum[4] = {0, 0, 0, 0};
	for (int i = 0; i < blocks; i++, ptr_a += 1, ptr_b += 1)
	{
		Vec X = _mm_load_si128(ptr_a);
		Vec Y = _mm_load_si128(ptr_b);
		X = _mm_xor_si128(X, Y);
		sum[0] += __builtin_popcount(_mm_extract_epi32(X, 0));
		sum[1] += __builtin_popcount(_mm_extract_epi32(X, 1));
		sum[2] += __builtin_popcount(_mm_extract_epi32(X, 2));
		sum[3] += __builtin_popcount(_mm_extract_epi32(X, 3));
	}
	int ans = sum[0] + sum[1] + sum[2] + sum[3];
	for (int i = blocks * 128; i < len; i++)
		ans += (a.get(pa + i) ^ b.get(pb + i));
	return ans;
}

char str[N];

void read(BitSet *b)
{
	scanf(" %s", str);
	int len = strlen(str);
	for (int i = 0; i < SHIFTS; i++)
	{
		for (int s = i; s < len; s++)
		{
			if (str[s] == '1')
				b[i].set(s - i);
		}
	}
}

int main()
{
	read(A);
	read(B);
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		int p1, p2, len;
		scanf("%d%d%d", &p1, &p2, &len);
		int r1 = p1 % SHIFTS;
		int r2 = p2 % SHIFTS;

		printf("%d\n", getDistance(A[r1], B[r2], p1 - r1, p2 - r2, len));
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

namespace fft {
  typedef double dbl;

  struct num {
    dbl x, y;
    num() { x = y = 0; }
    num(dbl x, dbl y) : x(x), y(y) { }
  };

  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
  inline num conj(num a) { return num(a.x, -a.y); }

  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};

  const dbl PI = acosl(-1.0);

  void ensure_base(int nbase) {
    if (nbase <= base) {
      return;
    }
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++) {
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    }
    roots.resize(1 << nbase);
    while (base < nbase) {
      dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
        dbl angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &a, int n = -1) {
    if (n == -1) {
      n = a.size();
    }
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++) {
      if (i < (rev[i] >> shift)) {
        swap(a[i], a[rev[i] >> shift]);
      }
    }
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }

  vector<num> fa, fb;

  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int) fa.size()) {
      fa.resize(sz);
    }
    for (int i = 0; i < sz; i++) {
      int x = (i < (int) a.size() ? a[i] : 0);
      int y = (i < (int) b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) {
        fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      }
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
    }
    return res;
  }
};

const int N = 2e5 + 5;
const int K = 5000;
const int MASK = (1 << 16) - 1;

int n, m, q;
char a[N], b[N];
int cnt[N];
unsigned a1[32][N >> 5], a2[32][N >> 5];
vector < int > mul[N / K + 5];

int get(int l, int r, int len) {
  int ans = 0;
  while(len >= 32 and l % K != 1 and l % K and ((l + 32) % K > l % K or (l + 32) % K == 0)) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while(len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while(len >= 32) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}

int main() {
  for(int i = 1; i < (1 << 16); i++)
    cnt[i] = cnt[i - (i & -i)] + 1;
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < n; i++)
      if(a[i + j + 1] == '1')
        a1[j][i >> 5] |= 1 << (i & 31);
  }
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < m; i++)
      if(b[i + j + 1] == '1')
        a2[j][i >> 5] |= 1 << (i & 31);
  }
  auto upd = [&](char s[N], int n) {
    for(int i = 1; i <= n; i++) {
      if(s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector < int > v;
    for(int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector < int > vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for(int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector < int > va = getVec(a, i, end);
    mul[id] = fft :: multiply(va, vb);
  }
  scanf("%d", &q);
  for(int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

namespace fft {
  typedef double dbl;

  struct num {
    dbl x, y;
    num() { x = y = 0; }
    num(dbl x, dbl y) : x(x), y(y) { }
  };

  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
  inline num conj(num a) { return num(a.x, -a.y); }

  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};

  const dbl PI = acosl(-1.0);

  void ensure_base(int nbase) {
    if (nbase <= base) {
      return;
    }
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++) {
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    }
    roots.resize(1 << nbase);
    while (base < nbase) {
      dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
        dbl angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &a, int n = -1) {
    if (n == -1) {
      n = a.size();
    }
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++) {
      if (i < (rev[i] >> shift)) {
        swap(a[i], a[rev[i] >> shift]);
      }
    }
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }

  vector<num> fa, fb;

  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int) fa.size()) {
      fa.resize(sz);
    }
    for (int i = 0; i < sz; i++) {
      int x = (i < (int) a.size() ? a[i] : 0);
      int y = (i < (int) b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) {
        fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      }
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
    }
    return res;
  }
};

const int N = 2e5 + 5;
const int K = 2500;
const int MASK = (1 << 16) - 1;

int n, m, q;
char a[N], b[N];
int cnt[N];
unsigned a1[32][N >> 5], a2[32][N >> 5];
vector < int > mul[N / K + 5];

int get(int l, int r, int len) {
  int ans = 0;
  while(len >= 32 and l % K != 1 and l % K and ((l + 32) % K > l % K or (l + 32) % K == 0)) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while(len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while(len >= 32) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}

int main() {
  for(int i = 1; i < (1 << 16); i++)
    cnt[i] = cnt[i - (i & -i)] + 1;
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < n; i++)
      if(a[i + j + 1] == '1')
        a1[j][i >> 5] |= 1 << (i & 31);
  }
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < m; i++)
      if(b[i + j + 1] == '1')
        a2[j][i >> 5] |= 1 << (i & 31);
  }
  auto upd = [&](char s[N], int n) {
    for(int i = 1; i <= n; i++) {
      if(s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector < int > v;
    for(int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector < int > vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for(int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector < int > va = getVec(a, i, end);
    mul[id] = fft :: multiply(va, vb);
  }
  scanf("%d", &q);
  for(int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

namespace fft {
  typedef double dbl;

  struct num {
    dbl x, y;
    num() { x = y = 0; }
    num(dbl x, dbl y) : x(x), y(y) { }
  };

  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
  inline num conj(num a) { return num(a.x, -a.y); }

  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};

  const dbl PI = acosl(-1.0);

  void ensure_base(int nbase) {
    if (nbase <= base) {
      return;
    }
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++) {
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    }
    roots.resize(1 << nbase);
    while (base < nbase) {
      dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
        dbl angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &a, int n = -1) {
    if (n == -1) {
      n = a.size();
    }
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++) {
      if (i < (rev[i] >> shift)) {
        swap(a[i], a[rev[i] >> shift]);
      }
    }
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }

  vector<num> fa, fb;

  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int) fa.size()) {
      fa.resize(sz);
    }
    for (int i = 0; i < sz; i++) {
      int x = (i < (int) a.size() ? a[i] : 0);
      int y = (i < (int) b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) {
        fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      }
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      res[i] = fa[i].x + 0.5;
    }
    return res;
  }
};

const int N = 2e5 + 5;
const int K = 3;

int n, m, q;
char a[N], b[N + N];
vector < int > mul[N / K + 5];

int get(int l, int r, int len) {
  int ans = 0;
  while(len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while(len >= K) {
    int id = (l - 1) / K;
    int dif = r - l;
    int i = m + 1 - dif;
    if(0 <= i and i < mul[id].size())
      ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while(len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}

int main() {
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  auto upd = [&](char s[N], int n) {
    for(int i = 1; i <= n; i++) {
      if(s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector < int > v;
    for(int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector < int > vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for(int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector < int > va = getVec(a, i, end);
    mul[id] = fft :: multiply(va, vb);
  }
  scanf("%d", &q);
  for(int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

namespace fft {
  typedef double dbl;

  struct num {
    dbl x, y;
    num() { x = y = 0; }
    num(dbl x, dbl y) : x(x), y(y) { }
  };

  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
  inline num conj(num a) { return num(a.x, -a.y); }

  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};

  const dbl PI = acosl(-1.0);

  void ensure_base(int nbase) {
    if (nbase <= base) {
      return;
    }
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++) {
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    }
    roots.resize(1 << nbase);
    while (base < nbase) {
      dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
        dbl angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &a, int n = -1) {
    if (n == -1) {
      n = a.size();
    }
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++) {
      if (i < (rev[i] >> shift)) {
        swap(a[i], a[rev[i] >> shift]);
      }
    }
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }

  vector<num> fa, fb;

  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int) fa.size()) {
      fa.resize(sz);
    }
    for (int i = 0; i < sz; i++) {
      int x = (i < (int) a.size() ? a[i] : 0);
      int y = (i < (int) b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) {
        fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      }
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
    }
    return res;
  }
};

const int N = 2e5 + 5;
const int K = 5000;

int n, m, q;
char a[N], b[N];
vector < int > mul[N / K + 5];

int get(int l, int r, int len) {
  int ans = 0;
  while(len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while(len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while(len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}

int main() {
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  auto upd = [&](char s[N], int n) {
    for(int i = 1; i <= n; i++) {
      if(s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector < int > v;
    for(int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector < int > vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for(int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector < int > va = getVec(a, i, end);
    mul[id] = fft :: multiply(va, vb);
  }
  scanf("%d", &q);
  for(int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

namespace fft {
  typedef double dbl;

  struct num {
    dbl x, y;
    num() { x = y = 0; }
    num(dbl x, dbl y) : x(x), y(y) { }
  };

  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
  inline num conj(num a) { return num(a.x, -a.y); }

  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};

  const dbl PI = acosl(-1.0);

  void ensure_base(int nbase) {
    if (nbase <= base) {
      return;
    }
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++) {
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    }
    roots.resize(1 << nbase);
    while (base < nbase) {
      dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
        dbl angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &a, int n = -1) {
    if (n == -1) {
      n = a.size();
    }
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++) {
      if (i < (rev[i] >> shift)) {
        swap(a[i], a[rev[i] >> shift]);
      }
    }
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }

  vector<num> fa, fb;

  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int) fa.size()) {
      fa.resize(sz);
    }
    for (int i = 0; i < sz; i++) {
      int x = (i < (int) a.size() ? a[i] : 0);
      int y = (i < (int) b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) {
        fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      }
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
    }
    return res;
  }
};

const int N = 2e5 + 5;
const int K = 7000;
const int MASK = (1 << 16) - 1;

int n, m, q;
char a[N], b[N];
int cnt[N];
unsigned a1[32][N >> 5], a2[32][N >> 5];
vector < int > mul[N / K + 5];

int get(int l, int r, int len) {
  int ans = 0;
  while(len >= 32 and l % K != 1 and l % K and ((l + 32) % K > l % K or (l + 32) % K == 0)) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while(len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while(len >= 32) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}

int main() {
  for(int i = 1; i < (1 << 16); i++)
    cnt[i] = cnt[i - (i & -i)] + 1;
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < n; i++)
      if(a[i + j + 1] == '1')
        a1[j][i >> 5] |= 1 << (i & 31);
  }
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < m; i++)
      if(b[i + j + 1] == '1')
        a2[j][i >> 5] |= 1 << (i & 31);
  }
  auto upd = [&](char s[N], int n) {
    for(int i = 1; i <= n; i++) {
      if(s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector < int > v;
    for(int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector < int > vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for(int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector < int > va = getVec(a, i, end);
    mul[id] = fft :: multiply(va, vb);
  }
  scanf("%d", &q);
  for(int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

namespace fft {
  typedef double dbl;

  struct num {
    dbl x, y;
    num() { x = y = 0; }
    num(dbl x, dbl y) : x(x), y(y) { }
  };

  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
  inline num conj(num a) { return num(a.x, -a.y); }

  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};

  const dbl PI = acosl(-1.0);

  void ensure_base(int nbase) {
    if (nbase <= base) {
      return;
    }
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++) {
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    }
    roots.resize(1 << nbase);
    while (base < nbase) {
      dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
        dbl angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &a, int n = -1) {
    if (n == -1) {
      n = a.size();
    }
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++) {
      if (i < (rev[i] >> shift)) {
        swap(a[i], a[rev[i] >> shift]);
      }
    }
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }

  vector<num> fa, fb;

  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int) fa.size()) {
      fa.resize(sz);
    }
    for (int i = 0; i < sz; i++) {
      int x = (i < (int) a.size() ? a[i] : 0);
      int y = (i < (int) b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) {
        fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      }
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
    }
    return res;
  }
};

const int N = 2e5 + 5;
const int K = 5000;
const int MASK = (1 << 16) - 1;

int n, m, q;
char a[N], b[N];
int cnt[N];
unsigned a1[32][N >> 5], a2[32][N >> 5];
vector < int > mul[N / K + 5];

int get(int l, int r, int len) {
  int ans = 0;
  while(len >= 32 and l % K != 1 and l % K and ((l + 32) % K > l % K or (l + 32) % K == 0)) {
    int w1 = l & 31;
    int w2 = r & 31;
    int x = l >> 5;
    int y = r >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while(len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while(len >= 32 and l % K != 1 and l % K and ((l + 32) % K > l % K or (l + 32) % K == 0)) {
    int w1 = l & 31;
    int w2 = r & 31;
    int x = l >> 5;
    int y = r >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}

int main() {
  for(int i = 1; i < (1 << 16); i++)
    cnt[i] = cnt[i - (i & -i)] + 1;
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for(int j = 0; j < 32; j++) {
    for(int i = 1; i + j <= n; i++)
      if(a[i + j] == '1')
        a1[j][i >> 5] |= 1 << (i & 31);
  }
  for(int j = 0; j < 32; j++) {
    for(int i = 1; i + j <= m; i++)
      if(b[i + j] == '1')
        a2[j][i >> 5] |= 1 << (i & 31);
  }
  auto upd = [&](char s[N], int n) {
    for(int i = 1; i <= n; i++) {
      if(s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector < int > v;
    for(int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector < int > vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for(int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector < int > va = getVec(a, i, end);
    mul[id] = fft :: multiply(va, vb);
  }
  scanf("%d", &q);
  for(int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

namespace fft {
  typedef double dbl;

  struct num {
    dbl x, y;
    num() { x = y = 0; }
    num(dbl x, dbl y) : x(x), y(y) { }
  };

  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
  inline num conj(num a) { return num(a.x, -a.y); }

  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};

  const dbl PI = acosl(-1.0);

  void ensure_base(int nbase) {
    if (nbase <= base) {
      return;
    }
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++) {
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    }
    roots.resize(1 << nbase);
    while (base < nbase) {
      dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
        dbl angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &a, int n = -1) {
    if (n == -1) {
      n = a.size();
    }
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++) {
      if (i < (rev[i] >> shift)) {
        swap(a[i], a[rev[i] >> shift]);
      }
    }
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }

  vector<num> fa, fb;

  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int) fa.size()) {
      fa.resize(sz);
    }
    for (int i = 0; i < sz; i++) {
      int x = (i < (int) a.size() ? a[i] : 0);
      int y = (i < (int) b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) {
        fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      }
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
    }
    return res;
  }
};

const int N = 2e5 + 5;
const int K = 5000;
const int MASK = (1 << 16) - 1;

int n, m, q;
char a[N], b[N];
int cnt[N];
unsigned a1[32][N >> 5], a2[32][N >> 5];
vector < int > mul[N / K + 5];

int get(int l, int r, int len) {
  int ans = 0;
  // while(len >= 32 and l % K != 1 and l % K and ((l + 32) % K > l % K or (l + 32) % K == 0)) {
  //   int w1 = l & 31;
  //   int w2 = r & 31;
  //   int x = l >> 5;
  //   int y = r >> 5;
  //   unsigned mask = a1[w1][x] ^ a2[w2][y];
  //   ans += cnt[mask & MASK] + cnt[mask >> 16];
  //   l += 32;
  //   r += 32;
  //   len -= 32;
  // }
  while(len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while(len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while(len >= 32) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while(len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}

int main() {
  for(int i = 1; i < (1 << 16); i++)
    cnt[i] = cnt[i - (i & -i)] + 1;
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < n; i++)
      if(a[i + j + 1] == '1')
        a1[j][i >> 5] |= 1 << (i & 31);
  }
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < m; i++)
      if(b[i + j + 1] == '1')
        a2[j][i >> 5] |= 1 << (i & 31);
  }
  auto upd = [&](char s[N], int n) {
    for(int i = 1; i <= n; i++) {
      if(s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector < int > v;
    for(int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector < int > vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for(int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector < int > va = getVec(a, i, end);
    mul[id] = fft :: multiply(va, vb);
  }
  scanf("%d", &q);
  for(int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

namespace fft {
  typedef double dbl;

  struct num {
    dbl x, y;
    num() { x = y = 0; }
    num(dbl x, dbl y) : x(x), y(y) { }
  };

  inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
  inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
  inline num operator*(num a, num b) { return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
  inline num conj(num a) { return num(a.x, -a.y); }

  int base = 1;
  vector<num> roots = {{0, 0}, {1, 0}};
  vector<int> rev = {0, 1};

  const dbl PI = acosl(-1.0);

  void ensure_base(int nbase) {
    if (nbase <= base) {
      return;
    }
    rev.resize(1 << nbase);
    for (int i = 0; i < (1 << nbase); i++) {
      rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
    }
    roots.resize(1 << nbase);
    while (base < nbase) {
      dbl angle = 2 * PI / (1 << (base + 1));
//      num z(cos(angle), sin(angle));
      for (int i = 1 << (base - 1); i < (1 << base); i++) {
        roots[i << 1] = roots[i];
//        roots[(i << 1) + 1] = roots[i] * z;
        dbl angle_i = angle * (2 * i + 1 - (1 << base));
        roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
      }
      base++;
    }
  }

  void fft(vector<num> &a, int n = -1) {
    if (n == -1) {
      n = a.size();
    }
    assert((n & (n - 1)) == 0);
    int zeros = __builtin_ctz(n);
    ensure_base(zeros);
    int shift = base - zeros;
    for (int i = 0; i < n; i++) {
      if (i < (rev[i] >> shift)) {
        swap(a[i], a[rev[i] >> shift]);
      }
    }
    for (int k = 1; k < n; k <<= 1) {
      for (int i = 0; i < n; i += 2 * k) {
        for (int j = 0; j < k; j++) {
          num z = a[i + j + k] * roots[j + k];
          a[i + j + k] = a[i + j] - z;
          a[i + j] = a[i + j] + z;
        }
      }
    }
  }

  vector<num> fa, fb;

  vector<int> multiply(vector<int> &a, vector<int> &b) {
    int need = a.size() + b.size() - 1;
    int nbase = 0;
    while ((1 << nbase) < need) nbase++;
    ensure_base(nbase);
    int sz = 1 << nbase;
    if (sz > (int) fa.size()) {
      fa.resize(sz);
    }
    for (int i = 0; i < sz; i++) {
      int x = (i < (int) a.size() ? a[i] : 0);
      int y = (i < (int) b.size() ? b[i] : 0);
      fa[i] = num(x, y);
    }
    fft(fa, sz);
    num r(0, -0.25 / sz);
    for (int i = 0; i <= (sz >> 1); i++) {
      int j = (sz - i) & (sz - 1);
      num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
      if (i != j) {
        fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
      }
      fa[i] = z;
    }
    fft(fa, sz);
    vector<int> res(need);
    for (int i = 0; i < need; i++) {
      res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
    }
    return res;
  }
};

const int N = 2e5 + 5;
const int K = 5000;
const int MASK = (1 << 16) - 1;

int n, m, q;
char a[N], b[N];
int cnt[N];
unsigned a1[32][N >> 5], a2[32][N >> 5];
vector < int > mul[N / K + 5];

int get(int l, int r, int len) {
  int ans = 0;
  // while(len >= 32 and l % K != 1 and l % K and ((l + 32) % K > l % K or (l + 32) % K == 0)) {
  //   int w1 = l & 31;
  //   int w2 = r & 31;
  //   int x = l >> 5;
  //   int y = r >> 5;
  //   unsigned mask = a1[w1][x] ^ a2[w2][y];
  //   ans += cnt[mask & MASK] + cnt[mask >> 16];
  //   l += 32;
  //   r += 32;
  //   len -= 32;
  // }
  while(len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while(len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  // while(len >= 32) {
  //   int w1 = (l - 1) & 31;
  //   int w2 = (r - 1) & 31;
  //   int x = (l - 1) >> 5;
  //   int y = (r - 1) >> 5;
  //   unsigned mask = a1[w1][x] ^ a2[w2][y];
  //   ans += cnt[mask & MASK] + cnt[mask >> 16];
  //   l += 32;
  //   r += 32;
  //   len -= 32;
  // }
  while(len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}

int main() {
  for(int i = 1; i < (1 << 16); i++)
    cnt[i] = cnt[i - (i & -i)] + 1;
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < n; i++)
      if(a[i + j] == '1')
        a1[j][i >> 5] |= 1 << (i & 31);
  }
  for(int j = 0; j < 32; j++) {
    for(int i = 0; i + j < m; i++)
      if(b[i + j] == '1')
        a2[j][i >> 5] |= 1 << (i & 31);
  }
  auto upd = [&](char s[N], int n) {
    for(int i = 1; i <= n; i++) {
      if(s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector < int > v;
    for(int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector < int > vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for(int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector < int > va = getVec(a, i, end);
    mul[id] = fft :: multiply(va, vb);
  }
  scanf("%d", &q);
  for(int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}