#include <stdio.h>
#include <bits/stdtr1c++.h>

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define dbg(x) cout << #x << " = " << x << endl
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))

using namespace std;

const int MASK = ~0U;
const int MAX = 222222;
const int MAXN = 1 << 20;
const int BLOCK = 1 << 14;

namespace fft{
    int len, last = -1, step = 0, rev[MAXN];
    long long C[MAXN], D[MAXN], P[MAXN], Q[MAXN];

	struct complx{
        double real, img;

        inline complx(){
            real = img = 0.0;
        }

        inline complx conjugate(){
            return complx(real, -img);
        }

        inline complx(double x){
            real = x, img = 0.0;
        }

        inline complx(double x, double y){
            real = x, img = y;
        }

        inline complx operator + (complx other){
            return complx(real + other.real, img + other.img);
        }

        inline complx operator - (complx other){
            return complx(real - other.real, img - other.img);
        }

        inline complx operator * (complx other){
            return complx((real * other.real) - (img * other.img), (real * other.img) + (img * other.real));
        }
    } u[MAXN], v[MAXN], f[MAXN], g[MAXN], dp[MAXN], inv[MAXN];

    void build(int& a, long long* A, int& b, long long* B){
        while (a > 1 && A[a - 1] == 0) a--;
        while (b > 1 && B[b - 1] == 0) b--;

	    len = 1 << (32 - __builtin_clz(a + b) - (__builtin_popcount(a + b) == 1));
        for (int i = a; i < len; i++) A[i] = 0;
        for (int i = b; i < len; i++) B[i] = 0;

		if (!step++){
            dp[1] = inv[1] = complx(1);
            for (int i = 1; (1 << i) < MAXN; i++){
                double theta = (2.0 * acos(0.0)) / (1 << i);
                complx mul = complx(cos(theta), sin(theta));
                complx inv_mul = complx(cos(-theta), sin(-theta));

                int lim = 1 << i;
                for (int j = lim >> 1; j < lim; j++){
                    dp[2 * j] = dp[j], inv[2 * j] = inv[j];
                    inv[2 * j + 1] = inv[j] * inv_mul;
                    dp[2 * j + 1] = dp[j] * mul;
                }
            }
        }

        if (last != len){
            last = len;
            int bit = (32 - __builtin_clz(len) - (__builtin_popcount(len) == 1));
            for (int i = 0; i < len; i++) rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (bit - 1));
        }
	}

	void transform_unrolled(complx *in, complx *out, complx* ar){
	    for (int i = 0; i < len; i++) out[i] = in[rev[i]];
	    for (int k = 1; k < len; k <<= 1){
            for (int i = 0; i < len; i += (k << 1)){
                complx z, *a = out + i, *b = out + i + k, *c = ar + k;
                if (k == 1){
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                }

                for (int j = 0; j < k && k > 1; j += 2, a++, b++, c++){
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                    a++, b++, c++;
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                }
            }
	    }
	}

	int multiply(int a, long long* A, int b, long long* B){
		build(a, A, b, B);
		for (int i = 0; i < len; i++) u[i] = complx(A[i], B[i]);
		transform_unrolled(u, f, dp);
		for (int i = 0; i < len; i++){
            int j = (len - 1) & (len - i);
            u[i] = (f[j] * f[j] - f[i].conjugate() * f[i].conjugate()) * complx(0, -0.25 / len);
		}
		transform_unrolled(u, f, dp);
		for (int i = 0; i < len; i++) A[i] = f[i].real + 0.5;
		return a + b - 1;
	}

	vector <int> hamming_distance(const char* str, const char* pattern){
        int n = strlen(str), m = strlen(pattern);
        for (int i = 0; i < n; i++) P[i] = Q[i] = 0;
        for (int i = 0; i < n; i++) P[i] = str[i] == '1' ? 1 : -1;
        for (int i = 0, j = m - 1; j >= 0; i++, j--) Q[i] = pattern[j] == '1' ? 1 : -1;

        vector <int> res;
        fft::multiply(n, P, m, Q);
        for (int i = 0; (i + m) <= n; i++){
            res.push_back(m - ((P[i + m - 1] + m) >> 1));
        }
        return res;
	}
}

char A[MAX], B[MAX], T[MAX];
unsigned long long dpA[MAX], dpB[MAX];
int n, m, r, sum[MAX], start[MAX], dp[MAX / BLOCK][MAX];

inline int popcount(int x){
    int counter = 0;
    __asm__ volatile ("POPCNT %1, %0;"
        :"=r"(counter)
        :"r"(x)
        :
    );
    return counter;
}

void generate(int n, const char* str, unsigned long long dp[MAX]){
    clr(dp);
    for (int i = 0; (i + 64) <= n; i++){
        for (int j = 0; j < 64; j++){
            if (str[i + j] == '1') dp[i] |= (1LL << j);
        }
    }
}

void generate(){
    int i, j, k, l;
    for (i = 0, r = 0; i < m; i++){
        start[i] = -1;
        if ((i % BLOCK) == 0) start[i] = r++;
    }

    for (i = 0; i < m; i++){
        if (start[i] != -1 && (i + BLOCK) <= m){
            for (j = 0; j < BLOCK; j++) T[j] = B[i + j];
            T[BLOCK] = 0;
            vector <int> v = fft::hamming_distance(A, T);
            for (j = 0; j < v.size(); j++) dp[start[i]][j] = v[j];
        }
    }
    for (i = 0; i < m; i++){
        sum[i] = (start[i] != -1);
        if (i) sum[i] += sum[i - 1];
    }

    generate(n, A, dpA);
    generate(m, B, dpB);
}

int solve(int i, int j, int l, int r){
    int res = 0;
    while (l <= r){
        if (start[l] != -1 && (l + BLOCK - 1) <= r){
            res += dp[start[l]][i];
            i += BLOCK, l += BLOCK;
        }
        else if (l && (l + 63) <= r && (sum[l + 63] - sum[l - 1]) == 0){
            unsigned long long x = dpA[i] ^ dpB[l];
            i += 64, l += 64;
            res = res + popcount(x >> 32) + popcount(x & MASK);
        }
        else{
            if (A[i] != B[l]) res++;
            i++, l++;
        }
    }
    return res;
}

int main(){
    int q, i, j, k, l;

    scanf("%s %s", A, B);
    n = strlen(A), m = strlen(B);
    generate();

    scanf("%d", &q);
    while (q--){
        scanf("%d %d %d", &i, &j, &l);
        printf("%d\n", solve(i, i + l - 1, j, j + l - 1));
    }
    return 0;
}


#include <stdio.h>
#include <bits/stdtr1c++.h>

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define dbg(x) cout << #x << " = " << x << endl
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))

using namespace std;

const int MASK = ~0U;
const int MAX = 222222;
const int MAXN = 1 << 20;
const int BLOCK = 1 << 12;

namespace fft{
    int len, last = -1, step = 0, rev[MAXN];
    long long C[MAXN], D[MAXN], P[MAXN], Q[MAXN];

	struct complx{
        double real, img;

        inline complx(){
            real = img = 0.0;
        }

        inline complx conjugate(){
            return complx(real, -img);
        }

        inline complx(double x){
            real = x, img = 0.0;
        }

        inline complx(double x, double y){
            real = x, img = y;
        }

        inline complx operator + (complx other){
            return complx(real + other.real, img + other.img);
        }

        inline complx operator - (complx other){
            return complx(real - other.real, img - other.img);
        }

        inline complx operator * (complx other){
            return complx((real * other.real) - (img * other.img), (real * other.img) + (img * other.real));
        }
    } u[MAXN], v[MAXN], f[MAXN], g[MAXN], dp[MAXN], inv[MAXN];

    void build(int& a, long long* A, int& b, long long* B){
        while (a > 1 && A[a - 1] == 0) a--;
        while (b > 1 && B[b - 1] == 0) b--;

	    len = 1 << (32 - __builtin_clz(a + b) - (__builtin_popcount(a + b) == 1));
        for (int i = a; i < len; i++) A[i] = 0;
        for (int i = b; i < len; i++) B[i] = 0;

		if (!step++){
            dp[1] = inv[1] = complx(1);
            for (int i = 1; (1 << i) < MAXN; i++){
                double theta = (2.0 * acos(0.0)) / (1 << i);
                complx mul = complx(cos(theta), sin(theta));
                complx inv_mul = complx(cos(-theta), sin(-theta));

                int lim = 1 << i;
                for (int j = lim >> 1; j < lim; j++){
                    dp[2 * j] = dp[j], inv[2 * j] = inv[j];
                    inv[2 * j + 1] = inv[j] * inv_mul;
                    dp[2 * j + 1] = dp[j] * mul;
                }
            }
        }

        if (last != len){
            last = len;
            int bit = (32 - __builtin_clz(len) - (__builtin_popcount(len) == 1));
            for (int i = 0; i < len; i++) rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (bit - 1));
        }
	}

	void transform_unrolled(complx *in, complx *out, complx* ar){
	    for (int i = 0; i < len; i++) out[i] = in[rev[i]];
	    for (int k = 1; k < len; k <<= 1){
            for (int i = 0; i < len; i += (k << 1)){
                complx z, *a = out + i, *b = out + i + k, *c = ar + k;
                if (k == 1){
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                }

                for (int j = 0; j < k && k > 1; j += 2, a++, b++, c++){
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                    a++, b++, c++;
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                }
            }
	    }
	}

	int multiply(int a, long long* A, int b, long long* B){
		build(a, A, b, B);
		for (int i = 0; i < len; i++) u[i] = complx(A[i], B[i]);
		transform_unrolled(u, f, dp);
		for (int i = 0; i < len; i++){
            int j = (len - 1) & (len - i);
            u[i] = (f[j] * f[j] - f[i].conjugate() * f[i].conjugate()) * complx(0, -0.25 / len);
		}
		transform_unrolled(u, f, dp);
		for (int i = 0; i < len; i++) A[i] = f[i].real + 0.5;
		return a + b - 1;
	}

	vector <int> hamming_distance(const char* str, const char* pattern){
        int n = strlen(str), m = strlen(pattern);
        for (int i = 0; i < n; i++) P[i] = Q[i] = 0;
        for (int i = 0; i < n; i++) P[i] = str[i] == '1' ? 1 : -1;
        for (int i = 0, j = m - 1; j >= 0; i++, j--) Q[i] = pattern[j] == '1' ? 1 : -1;

        vector <int> res;
        fft::multiply(n, P, m, Q);
        for (int i = 0; (i + m) <= n; i++){
            res.push_back(m - ((P[i + m - 1] + m) >> 1));
        }
        return res;
	}
}

char A[MAX], B[MAX], T[MAX];
unsigned long long dpA[MAX], dpB[MAX];
int n, m, r, sum[MAX], start[MAX], dp[MAX / BLOCK][MAX];

inline int popcount(int x){
    int counter = 0;
    __asm__ volatile ("POPCNT %1, %0;"
        :"=r"(counter)
        :"r"(x)
        :
    );
    return counter;
}

void generate(int n, const char* str, unsigned long long dp[MAX]){
    clr(dp);
    for (int i = 0; (i + 64) <= n; i++){
        for (int j = 0; j < 64; j++){
            if (str[i + j] == '1') dp[i] |= (1LL << j);
        }
    }
}

void generate(){
    int i, j, k, l;
    for (i = 0, r = 0; i < m; i++){
        start[i] = -1;
        if ((i % BLOCK) == 0) start[i] = r++;
    }

    for (i = 0; i < m; i++){
        if (start[i] != -1 && (i + BLOCK) <= m){
            for (j = 0; j < BLOCK; j++) T[j] = B[i + j];
            T[BLOCK] = 0;
            vector <int> v = fft::hamming_distance(A, T);
            for (j = 0; j < v.size(); j++) dp[start[i]][j] = v[j];
        }
    }
    for (i = 0; i < m; i++){
        sum[i] = (start[i] != -1);
        if (i) sum[i] += sum[i - 1];
    }

    generate(n, A, dpA);
    generate(m, B, dpB);
}

int solve(int i, int j, int l, int r){
    int res = 0;
    while (l <= r){
        if (start[l] != -1 && (l + BLOCK - 1) <= r){
            res += dp[start[l]][i];
            i += BLOCK, l += BLOCK;
        }
        else if (l && (l + 63) <= r && (sum[l + 63] - sum[l - 1]) == 0){
            unsigned long long x = dpA[i] ^ dpB[l];
            i += 64, l += 64;
            res = res + popcount(x >> 32) + popcount(x & MASK);
        }
        else{
            if (A[i] != B[l]) res++;
            i++, l++;
        }
    }
    return res;
}

int main(){
    int q, i, j, k, l;

    scanf("%s %s", A, B);
    n = strlen(A), m = strlen(B);
    generate();

    scanf("%d", &q);
    while (q--){
        scanf("%d %d %d", &i, &j, &l);
        printf("%d\n", solve(i, i + l - 1, j, j + l - 1));
    }
    return 0;
}


#include <stdio.h>
#include <bits/stdtr1c++.h>

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define dbg(x) cout << #x << " = " << x << endl
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))

using namespace std;

const int MASK = ~0U;
const int MAX = 222222;
const int MAXN = 1 << 20;
const int BLOCK = 6666;

namespace fft{
    int len, last = -1, step = 0, rev[MAXN];
    long long C[MAXN], D[MAXN], P[MAXN], Q[MAXN];

	struct complx{
        double real, img;

        inline complx(){
            real = img = 0.0;
        }

        inline complx conjugate(){
            return complx(real, -img);
        }

        inline complx(double x){
            real = x, img = 0.0;
        }

        inline complx(double x, double y){
            real = x, img = y;
        }

        inline complx operator + (complx other){
            return complx(real + other.real, img + other.img);
        }

        inline complx operator - (complx other){
            return complx(real - other.real, img - other.img);
        }

        inline complx operator * (complx other){
            return complx((real * other.real) - (img * other.img), (real * other.img) + (img * other.real));
        }
    } u[MAXN], v[MAXN], f[MAXN], g[MAXN], dp[MAXN], inv[MAXN];

    void build(int& a, long long* A, int& b, long long* B){
        while (a > 1 && A[a - 1] == 0) a--;
        while (b > 1 && B[b - 1] == 0) b--;

	    len = 1 << (32 - __builtin_clz(a + b) - (__builtin_popcount(a + b) == 1));
        for (int i = a; i < len; i++) A[i] = 0;
        for (int i = b; i < len; i++) B[i] = 0;

		if (!step++){
            dp[1] = inv[1] = complx(1);
            for (int i = 1; (1 << i) < MAXN; i++){
                double theta = (2.0 * acos(0.0)) / (1 << i);
                complx mul = complx(cos(theta), sin(theta));
                complx inv_mul = complx(cos(-theta), sin(-theta));

                int lim = 1 << i;
                for (int j = lim >> 1; j < lim; j++){
                    dp[2 * j] = dp[j], inv[2 * j] = inv[j];
                    inv[2 * j + 1] = inv[j] * inv_mul;
                    dp[2 * j + 1] = dp[j] * mul;
                }
            }
        }

        if (last != len){
            last = len;
            int bit = (32 - __builtin_clz(len) - (__builtin_popcount(len) == 1));
            for (int i = 0; i < len; i++) rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (bit - 1));
        }
	}

	void transform_unrolled(complx *in, complx *out, complx* ar){
	    for (int i = 0; i < len; i++) out[i] = in[rev[i]];
	    for (int k = 1; k < len; k <<= 1){
            for (int i = 0; i < len; i += (k << 1)){
                complx z, *a = out + i, *b = out + i + k, *c = ar + k;
                if (k == 1){
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                }

                for (int j = 0; j < k && k > 1; j += 2, a++, b++, c++){
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                    a++, b++, c++;
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                }
            }
	    }
	}

	int multiply(int a, long long* A, int b, long long* B){
		build(a, A, b, B);
		for (int i = 0; i < len; i++) u[i] = complx(A[i], B[i]);
		transform_unrolled(u, f, dp);
		for (int i = 0; i < len; i++){
            int j = (len - 1) & (len - i);
            u[i] = (f[j] * f[j] - f[i].conjugate() * f[i].conjugate()) * complx(0, -0.25 / len);
		}
		transform_unrolled(u, f, dp);
		for (int i = 0; i < len; i++) A[i] = f[i].real + 0.5;
		return a + b - 1;
	}

	vector <int> hamming_distance(const char* str, const char* pattern){
        int n = strlen(str), m = strlen(pattern);
        for (int i = 0; i < n; i++) P[i] = Q[i] = 0;
        for (int i = 0; i < n; i++) P[i] = str[i] == '1' ? 1 : -1;
        for (int i = 0, j = m - 1; j >= 0; i++, j--) Q[i] = pattern[j] == '1' ? 1 : -1;

        vector <int> res;
        fft::multiply(n, P, m, Q);
        for (int i = 0; (i + m) <= n; i++){
            res.push_back(m - ((P[i + m - 1] + m) >> 1));
        }
        return res;
	}
}

char A[MAX], B[MAX], T[MAX];
unsigned long long dpA[MAX], dpB[MAX];
int n, m, r, sum[MAX], start[MAX], dp[MAX / BLOCK][MAX];

inline int popcount(int x){
    int counter = 0;
    __asm__ volatile ("POPCNT %1, %0;"
        :"=r"(counter)
        :"r"(x)
        :
    );
    return counter;
}

void generate(int n, const char* str, unsigned long long dp[MAX]){
    clr(dp);
    for (int i = 0; (i + 64) <= n; i++){
        for (int j = 0; j < 64; j++){
            if (str[i + j] == '1') dp[i] |= (1LL << j);
        }
    }
}

void generate(){
    int i, j, k, l;
    for (i = 0, r = 0; i < m; i++){
        start[i] = -1;
        if ((i % BLOCK) == 0) start[i] = r++;
    }

    for (i = 0; i < m; i++){
        if (start[i] != -1 && (i + BLOCK) <= m){
            for (j = 0; j < BLOCK; j++) T[j] = B[i + j];
            T[BLOCK] = 0;
            vector <int> v = fft::hamming_distance(A, T);
            for (j = 0; j < v.size(); j++) dp[start[i]][j] = v[j];
        }
    }
    for (i = 0; i < m; i++){
        sum[i] = (start[i] != -1);
        if (i) sum[i] += sum[i - 1];
    }

    generate(n, A, dpA);
    generate(m, B, dpB);
}

int solve(int i, int j, int l, int r){
    int res = 0;
    while (l <= r){
        if (start[l] != -1 && (l + BLOCK - 1) <= r){
            res += dp[start[l]][i];
            i += BLOCK, l += BLOCK;
        }
        else if (l && (l + 63) <= r && (sum[l + 63] - sum[l - 1]) == 0){
            unsigned long long x = dpA[i] ^ dpB[l];
            i += 64, l += 64;
            res = res + popcount(x >> 32) + popcount(x & MASK);
        }
        else{
            if (A[i] != B[l]) res++;
            i++, l++;
        }
    }
    return res;
}

int main(){
    int q, i, j, k, l;

    scanf("%s %s", A, B);
    n = strlen(A), m = strlen(B);
    generate();

    scanf("%d", &q);
    while (q--){
        scanf("%d %d %d", &i, &j, &l);
        printf("%d\n", solve(i, i + l - 1, j, j + l - 1));
    }
    return 0;
}


#include <stdio.h>
#include <bits/stdtr1c++.h>

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define dbg(x) cout << #x << " = " << x << endl
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))

using namespace std;

const int MAX = 222222;
const int MAXN = 1 << 20;
const int BLOCK = 1 << 12;

namespace fft{
    int len, last = -1, step = 0, rev[MAXN];
    long long C[MAXN], D[MAXN], P[MAXN], Q[MAXN];

	struct complx{
        double real, img;

        inline complx(){
            real = img = 0.0;
        }

        inline complx conjugate(){
            return complx(real, -img);
        }

        inline complx(double x){
            real = x, img = 0.0;
        }

        inline complx(double x, double y){
            real = x, img = y;
        }

        inline complx operator + (complx other){
            return complx(real + other.real, img + other.img);
        }

        inline complx operator - (complx other){
            return complx(real - other.real, img - other.img);
        }

        inline complx operator * (complx other){
            return complx((real * other.real) - (img * other.img), (real * other.img) + (img * other.real));
        }
    } u[MAXN], v[MAXN], f[MAXN], g[MAXN], dp[MAXN], inv[MAXN];

    void build(int& a, long long* A, int& b, long long* B){
        while (a > 1 && A[a - 1] == 0) a--;
        while (b > 1 && B[b - 1] == 0) b--;

	    len = 1 << (32 - __builtin_clz(a + b) - (__builtin_popcount(a + b) == 1));
        for (int i = a; i < len; i++) A[i] = 0;
        for (int i = b; i < len; i++) B[i] = 0;

		if (!step++){
            dp[1] = inv[1] = complx(1);
            for (int i = 1; (1 << i) < MAXN; i++){
                double theta = (2.0 * acos(0.0)) / (1 << i);
                complx mul = complx(cos(theta), sin(theta));
                complx inv_mul = complx(cos(-theta), sin(-theta));

                int lim = 1 << i;
                for (int j = lim >> 1; j < lim; j++){
                    dp[2 * j] = dp[j], inv[2 * j] = inv[j];
                    inv[2 * j + 1] = inv[j] * inv_mul;
                    dp[2 * j + 1] = dp[j] * mul;
                }
            }
        }

        if (last != len){
            last = len;
            int bit = (32 - __builtin_clz(len) - (__builtin_popcount(len) == 1));
            for (int i = 0; i < len; i++) rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (bit - 1));
        }
	}

	void transform_unrolled(complx *in, complx *out, complx* ar){
	    for (int i = 0; i < len; i++) out[i] = in[rev[i]];
	    for (int k = 1; k < len; k <<= 1){
            for (int i = 0; i < len; i += (k << 1)){
                complx z, *a = out + i, *b = out + i + k, *c = ar + k;
                if (k == 1){
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                }

                for (int j = 0; j < k && k > 1; j += 2, a++, b++, c++){
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                    a++, b++, c++;
                    z = (*b) * (*c);
                    *b = *a - z, *a = *a + z;
                }
            }
	    }
	}

	int multiply(int a, long long* A, int b, long long* B){
		build(a, A, b, B);
		for (int i = 0; i < len; i++) u[i] = complx(A[i], B[i]);
		transform_unrolled(u, f, dp);
		for (int i = 0; i < len; i++){
            int j = (len - 1) & (len - i);
            u[i] = (f[j] * f[j] - f[i].conjugate() * f[i].conjugate()) * complx(0, -0.25 / len);
		}
		transform_unrolled(u, f, dp);
		for (int i = 0; i < len; i++) A[i] = f[i].real + 0.5;
		return a + b - 1;
	}

	vector <int> hamming_distance(const char* str, const char* pattern){
        int n = strlen(str), m = strlen(pattern);
        for (int i = 0; i < n; i++) P[i] = Q[i] = 0;
        for (int i = 0; i < n; i++) P[i] = str[i] == '1' ? 1 : -1;
        for (int i = 0, j = m - 1; j >= 0; i++, j--) Q[i] = pattern[j] == '1' ? 1 : -1;

        vector <int> res;
        fft::multiply(n, P, m, Q);
        for (int i = 0; (i + m) <= n; i++){
            res.push_back(m - ((P[i + m - 1] + m) >> 1));
        }
        return res;
	}
}

char A[MAX], B[MAX], T[MAX];
int n, m, r, len, start[MAX], dp[MAX / BLOCK][MAX];

void generate(){
    int i, j, k, l;
    for (i = 0, r = 0; i < m; i++){
        start[i] = -1;
        if ((i % BLOCK) == 0) start[i] = r++;
    }

    for (i = 0; i < m; i++){
        if (start[i] != -1 && (i + BLOCK) <= m){
            for (j = 0; j < BLOCK; j++) T[j] = B[i + j];
            T[BLOCK] = 0;
            vector <int> v = fft::hamming_distance(A, T);
            for (j = 0, len = v.size(); j < len; j++) dp[start[i]][j] = v[j];
        }
    }
}

int solve(int i, int j, int l, int r){
    int k, x, res = 0;
    while (l <= r){
        if (start[l] != -1 && (l + BLOCK - 1) <= r){
            res += dp[start[l]][i];
            i += BLOCK, l += BLOCK;
        }
        else{
            if (A[i] != B[l]) res++;
            i++, l++;
        }
    }
    return res;
}

int main(){
    int q, i, j, k, l;

    scanf("%s %s", A, B);
    n = strlen(A), m = strlen(B);
    generate();

    scanf("%d", &q);
    while (q--){
        scanf("%d %d %d", &i, &j, &l);
        printf("%d\n", solve(i, i + l - 1, j, j + l - 1));
    }
    return 0;
}


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = max(int(1.0 * n / q * sqrt(q * log2(n))), n / 250);
    block = min(block, min(n, m));
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i+block-1<n; i+=block, cnt ++) {
        l[cnt] = i; r[cnt] = i + block - 1;
        for(int j=0; j<block; j++) a[j] = (s[i + block - 1 - j ] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[cnt][j-block+1] = (block - c[j]) / 2;
    }
    l[cnt] = l[cnt - 1] + block;
    r[cnt] = r[cnt - 1] + block;
    cnt ++;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = lower_bound(l, l + cnt, p1) - l;
        int rpos = upper_bound(r, r + cnt, p1 + len - 1) - r - 1;
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos; i <= rpos; i++) ans += dis[i][l[i]];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++) ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--) ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
    return 0;
}


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 155;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 1500;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
//    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=r[indx[p1+len-1]]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
//    int t2 = clock(); cout << t2 - t1 << endl;
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = sqrt(n);
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i+block-1<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
    l[cnt] = l[cnt - 1] + block;
    r[cnt] = r[cnt - 1] + block;
    cnt ++;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p2+len-1] - (p2 !=indx[p2+len-1]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
    return 0;
}


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 155;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
//    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
//    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 3000;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
//    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=r[indx[p1+len-1]]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
//    int t2 = clock(); cout << t2 - t1 << endl;
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 2000;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i+block-1<n; i++) {
        if(i % block == 0) r[cnt] = i, l[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[cnt][j-block+1] = (block - c[j]) / 2;
    }
    l[cnt] = l[cnt - 1] + block;
    r[cnt] = r[cnt - 1] + block;
    cnt ++;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = lower_bound(l, l + cnt, p1) - l;
        int rpos = upper_bound(r, r + cnt, p1 + len - 1) - r - 1;
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
    return 0;
}


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 1000;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i+block-1<n; i+=block, cnt ++) {
        l[cnt] = i; r[cnt] = i + block - 1;
        for(int j=0; j<block; j++) a[j] = (s[i + block - 1 - j ] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[cnt][j-block+1] = (block - c[j]) / 2;
    }
    l[cnt] = l[cnt - 1] + block;
    r[cnt] = r[cnt - 1] + block;
    cnt ++;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = lower_bound(l, l + cnt, p1) - l;
        int rpos = upper_bound(r, r + cnt, p1 + len - 1) - r - 1;
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
    return 0;
}


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = max((int)sqrt(n), n / 250);
    block = min(block, min(n, m));
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i+block-1<n; i+=block, cnt ++) {
        l[cnt] = i; r[cnt] = i + block - 1;
        for(int j=0; j<block; j++) a[j] = (s[i + block - 1 - j ] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[cnt][j-block+1] = (block - c[j]) / 2;
    }
    l[cnt] = l[cnt - 1] + block;
    r[cnt] = r[cnt - 1] + block;
    cnt ++;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = lower_bound(l, l + cnt, p1) - l;
        int rpos = upper_bound(r, r + cnt, p1 + len - 1) - r - 1;
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos; i <= rpos; i++) ans += dis[i][l[i]];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++) ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--) ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
    return 0;
}


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 155;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
//    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
//    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 1800;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
//    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=r[indx[p1+len-1]]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
//    int t2 = clock(); cout << t2 - t1 << endl;
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
//    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
//    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 5000;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
//    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=indx[p1+len-1]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
//    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
//    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 1500;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=indx[p1+len-1]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
//    int t2 = clock(); cout << t2 - t1 << endl;
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
//    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
//    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 1500;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
//    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=indx[p1+len-1]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
//    int t2 = clock(); cout << t2 - t1 << endl;
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 155;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
//    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
//    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 1500;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
//    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=r[indx[p1+len-1]]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
//    int t2 = clock(); cout << t2 - t1 << endl;
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = max((int)sqrt(n), n / 250);
    block = min(block, min(n, m));
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i+block-1<n; i+=block, cnt ++) {
        l[cnt] = i; r[cnt] = i + block - 1;
        for(int j=0; j<block; j++) a[j] = (s[i + block - 1 - j ] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[cnt][j-block+1] = (block - c[j]) / 2;
    }
    l[cnt] = l[cnt - 1] + block;
    r[cnt] = r[cnt - 1] + block;
    cnt ++;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = lower_bound(l, l + cnt, p1) - l;
        int rpos = upper_bound(r, r + cnt, p1 + len - 1) - r - 1;
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
    return 0;
}


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 256;
int dis[maxm][maxn], l[maxm], r[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = max(int(1.0 * n / q * sqrt(q * log2(n))), n / 250);
    block = min(block, min(n, m));
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i+block-1<n; i+=block, cnt ++) {
        l[cnt] = i; r[cnt] = i + block - 1;
        for(int j=0; j<block; j++) a[j] = (s[i + block - 1 - j ] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=0; j<=m-block ; j++) dis[cnt][j] = (block - c[j]) / 2;
    }
    l[cnt] = l[cnt - 1] + block;
    r[cnt] = r[cnt - 1] + block;
    cnt ++;
    while(q -- ){
         int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
         int lpos = lower_bound(l, l + cnt, p1) - l;
         int rpos = upper_bound(r, r + cnt, p1 + len - 1) - r - 1;
         int ans = 0;
         if(rpos < lpos) {
             for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
         }else {
             for (int i = lpos; i <= rpos; i++) ans += dis[i][l[i]];
             for (int i = p1, j = p2; i < l[lpos]; i++, j++) ans += s[i] != t[j];
             for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--) ans += s[i] != t[j];
         }
         printf("%d\n", ans);
    }
    return 0;
}


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 155;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
//    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
//    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 5000;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
//    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=r[indx[p1+len-1]]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
//    int t2 = clock(); cout << t2 - t1 << endl;
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include <random>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
#include <complex>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double. int>
const int INF  =  0x3f3f3f3f;
const int mod  =  1e9 + 7;
const int maxn =  200000 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double eps = 1e-7;

namespace FFT_Mannix {

    int fm = 1, fl, fr[maxn << 2];

    struct CP {
        double x, y;
        inline CP friend operator + (CP x, CP y) { return (CP) {x.x + y.x, x.y + y.y}; }
        inline CP friend operator - (CP x, CP y) { return (CP) {x.x - y.x, x.y - y.y}; }
        inline CP friend operator * (CP x, CP y) { return (CP) {x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x}; }
    } fe[maxn << 2], ff[maxn << 2], fg[maxn << 2];

    inline CP rt(double X) { return (CP) {cos(X), sin(X)}; }

    void fft(CP *a, int t) { //先init()
        for (int i = 0; i < fm; ++i) fg[fr[i]] = a[i];
        for (int m = 2; m <= fm; m <<= 1) {
            CP w = rt(t * PI / m), u, v, z;
            for (int i, k = m >> 1, j = 0; j < fm; j += m) {
                for (z = (CP) {1, 0.0}, i = 0; i < k; ++i, z = z * w) {
                    u = fg[i + j];
                    v = z * fg[i + j + k];
                    fg[i + j] = u + v;
                    fg[i + j + k] = u - v;
                }
            }
        }
        memcpy(a, fg, fm * sizeof(CP));
    }

    void init(int n) { // n为乘积的最大次幂
        fm = 1, fl = 0;
        while (fm <= n) fm <<= 1, fl++;
        for (int i = 0; i < fm; i++) fr[i] = (fr[i >> 1] >> 1) | ((i & 1) << (fl - 1));
    }

    void conv(int *a, int n, int *b, int m, int *c) {
        init(n + m);
        for(int i=0; i < fm; i++) ff[i].x = ff[i].y = fe[i].x = fe[i].y = 0;
        for (int i = 0; i <= n; i++) fe[i].x = a[i];
        for (int i = 0; i <= m; i++) ff[i].x = b[i];
        fft(fe, 2);
        fft(ff, 2);
        for (int i = 0; i < fm; i++) fe[i] = fe[i] * ff[i];
        fft(fe, -2);
        for (int i = 0; i <= n+m; i++) c[i] = (int)(fe[i].x / fm + (fe[i].x > 0 ? 1 : -1) * 0.5);
    }
}

using namespace FFT_Mannix;

string s, t;
const int maxm = 155;
int dis[maxm][maxn], l[maxm], r[maxn], indx[maxn], cnt = 1;
int a[maxn], b[maxn], c[maxn << 1];

int main () {
//    freopen("/Users/mac/CLionProjects/project_hack_check/cmake-build-debug/1.txt", "r", stdin);
//    freopen("1.txt", "w", stdout);
    cin >> s >> t;
    int q; scanf("%d", &q);
    int n = s.length() , m = t.length() ;
    int block = 2000;
    for(int i=0; i<m; i++) b[i] = (t[i] == '1' ? 1 : -1);
    r[0] = -1; l[0] = -block;
    for(int i=0; i<n; i++) {
        if(i % block == 0) l[cnt] = i, r[cnt ++] = i + block - 1;
        indx[i] = cnt - 1;
    }
    for(int i=1; i<cnt-1; i++) {
        for(int j=0; j<block; j++) a[j] = (s[r[i]-j] == '1' ? 1 : -1);
        conv(a, block-1, b, m - 1, c);
        for(int j=block-1; j<=m-1; j++) dis[i][j-block+1] = (block - c[j]) / 2;
    }
//    int t1 = clock(); cout << t1 << endl;
    while(q -- ){
        int p1, p2, len; scanf("%d%d%d", &p1, &p2, &len);
        int lpos = indx[p1] + (p1 != l[indx[p1]]);
        int rpos = indx[p1+len-1] - (p1 !=r[indx[p1+len-1]]);
        int ans = 0;
        if(rpos < lpos) {
            for(int i=p1, j=p2; i<p1 + len; i++, j ++) ans += s[i] != t[j];
        }else {
            for (int i = lpos, d = p2+(l[lpos]-p1); i <= rpos; i++, d += block)
                ans += dis[i][d];
            for (int i = p1, j = p2; i < l[lpos]; i++, j++)
                ans += s[i] != t[j];
            for (int i = p1 + len - 1, j = p2 + len - 1; i > r[rpos]; i--, j--)
                ans += s[i] != t[j];
        }
        printf("%d\n", ans);
    }
//    int t2 = clock(); cout << t2 - t1 << endl;
    return 0;
}

/*
1101110001
0111100110
10
7 3 1
7 3 0
6 8 1
4 3 2
1 6 1
3 4 2
5 1 2
5 5 1
9 5 0
4 1 1

 */


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;

char A[MAXN], B[MAXN];
int n, m, q;
int a[MAXN], b[MAXN];
unsigned int xa[33][30000], xb[33][30000];
int cnt[MAXN];

namespace fio {
    const int BSIZE = 1048576;
    char buffer[BSIZE];
    int p = BSIZE;
    inline char readChar() {
        if(p == BSIZE) {
            fread(buffer, 1, BSIZE, stdin);
            p = 0;
        }
        return buffer[p++];
    }
    int readInt() {
        char c = readChar();
        while ((c < '0' || c > '9') && c != '-') {
            c = readChar();
        }
        int ret = 0; bool neg = c == '-';
        if (neg) c = readChar();
        while (c >= '0' && c <= '9') {
            ret = ret * 10 + c - '0';
            c = readChar();
        }
        return neg ? -ret : ret;
    }
}

int main() {
	scanf("%s%s", A, B);
	n = strlen(A), m = strlen(B);
	for (int i = 0; i < n; i++) a[i] = A[i]-'0';
	for (int i = 0; i < m; i++) b[i] = B[i]-'0';
	for (int i = 0; i < (1<<16); i++) {
		cnt[i] = __builtin_popcount(i);
	}
	for (int i = 0; i < 32; i++) {
		for (int j = n>>5; j >= 0; j--) {
            int l = (j<<5) + i;
			for (int k = 0; k < 32; k++, l++) xa[i][j] |= a[l]*(1<<k);
		}
		for(int j = m>>5; j >= 0; j--) {
            int l = (j<<5) + i;
			for(int k = 0; k < 32; k++, l++) xb[i][j] |= b[l]*(1<<k);
		}
	}
	q = fio::readInt();
	int x, y, z, x1, y1, x2, y2, g = 1<<16, g2 = (1<<16)-1;
	for (int i = 0; i < q; i++) {
		x = fio::readInt(); y = fio::readInt(); z = fio::readInt();
		int ans = 0;
		x1 = x&(31), y1 = y&(31); x2 = x>>5, y2 = y>>5;
		for (int j = 0; j < z/32; j++) {
			unsigned int u = (xa[x1][x2++]^xb[y1][y2++]);
			ans += cnt[u>>16] + cnt[u&g2];
		}
		for (int j = (z>>5)<<5; j < z; j++) ans += (a[x+j]^b[y+j]);
		printf("%d\n", ans);
	}
}


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

const int MAXN = 200035;

char A[MAXN], B[MAXN];
long long a[MAXN], b[MAXN];
int N, M;
const int T = 60;

map <tuple<int,int,int>, int> dp;

int main() {
	scanf("%s", A+1); N = strlen(A+1);
	scanf("%s", B+1); M = strlen(B+1);
	for (int i = N+1; i < MAXN; i++) A[i] = '0';
	for (int i = M+1; i < MAXN; i++) B[i] = '0';
	{
		long long x = 0;
		for (int i = 1; i <= T; i++) x = x*2 + (A[i]-'0');
		for (int i = 1; i <= N; i++) {
			a[i] = x;
			x -= (A[i]-'0')*((1LL)<<(T-1));
			x = x*2 + (A[i+T]-'0');
		}
	} {
		long long x = 0;
		for (int i = 1; i <= T; i++) x = x*2 + (B[i]-'0');
		for (int i = 1; i <= M; i++) {
			b[i] = x;
			x -= (B[i]-'0')*((1LL)<<(T-1));
			x = x*2 + (B[i+T]-'0');
		}
	}
	int Q; for (scanf("%d",&Q); Q--; ) {
		int p, q, L; scanf("%d%d%d",&p,&q,&L); p++; q++;
		if (dp.count({p, q, L})) {
			printf("%d\n", dp[{p, q, L}]);
			continue;
		}
		int ans = 0;
		while (L > 0) {
			if (L >= T) {
				ans += __builtin_popcountll(a[p]^b[q]);
				p += T; q += T; L -= T;
			} else {
				for (int i = 0; i < L; i++) {
					ans += (A[p+i] != B[q+i]);
				}
				L = 0;
			}
		}
		dp[{p, q, L}] = ans;
		printf("%d\n", ans);
	}
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;

char A[MAXN], B[MAXN];
int n, m, q;
int a[MAXN], b[MAXN];
unsigned int xa[33][30000], xb[33][30000];
int cnt[MAXN];

namespace fio {
    const int BSIZE = 524288;
    char buffer[BSIZE];
    int p = BSIZE;
    inline char readChar() {
        if(p == BSIZE) {
            fread(buffer, 1, BSIZE, stdin);
            p = 0;
        }
        return buffer[p++];
    }
    int readInt() {
        char c = readChar();
        while ((c < '0' || c > '9') && c != '-') {
            c = readChar();
        }
        int ret = 0; bool neg = c == '-';
        if (neg) c = readChar();
        while (c >= '0' && c <= '9') {
            ret = ret * 10 + c - '0';
            c = readChar();
        }
        return neg ? -ret : ret;
    }
}

int main() {
	scanf("%s%s", A, B);
	n = strlen(A), m = strlen(B);
	for (int i = 0; i < n; i++) a[i] = A[i]-'0';
	for (int i = 0; i < m; i++) b[i] = B[i]-'0';
	for (int i = 0; i < (1<<16); i++) {
		cnt[i] = __builtin_popcount(i);
	}
	for (int i = 0; i < 32; i++) {
		for (int j = n>>5; j >= 0; j--) {
			for (int k = 0; k < 32; k++) xa[i][j] |= a[j*32+i+k]*(1<<k);
		}
		for(int j = m>>5; j >= 0; j--) {
			for(int k = 0; k < 32; k++) xb[i][j] |= b[j*32+i+k]*(1<<k);
		}
	}
	q = fio::readInt();
	int x, y, z, x1, y1, x2, y2, g = 1<<16, g2 = (1<<16)-1;
	for (int i = 0; i < q; i++) {
		x = fio::readInt(); y = fio::readInt(); z = fio::readInt();
		int ans = 0;
		x1 = x&(31), y1 = y&(31); x2 = x>>5, y2 = y>>5;
		for (int j = 0; j < z/32; j++) {
			unsigned int u = (xa[x1][x2++]^xb[y1][y2++]);
			ans += cnt[u>>16] + cnt[u&g2];
		}
		for (int j = (z>>5)<<5; j < z; j++) ans += (a[x+j]^b[y+j]);
		printf("%d\n", ans);
	}
}


#include <bits/stdc++.h>
using namespace std;
const unsigned N=2e5;
unsigned a[32][N+31>>5];
unsigned b[32][N+31>>5];
char s[N+1];
static int pc(unsigned n){
    int c;
    __asm__("popcnt %0, %1" : "=r"(c) : "r"(n));
    return c;
}
unsigned get(unsigned p,unsigned q,unsigned len){
	unsigned x=p>>5, y=q>>5, c=0;
	p&=31; q&=31;
	while(len>=32){
		c+=pc(a[p][x]^b[q][y]);
		++x, ++y;
		len-=32;
	}
	c+=pc((a[p][x]^b[q][y])&((1u<<len)-1));
	return c;
}
int main(){
	int n, m, q, p1, p2, len;
	scanf("%s",s); n=strlen(s);
	for(int i=0;i<32;++i){
    	for(int j=0;i+j<n;++j){
      		if(s[i+j]=='1')
				a[i][j>>5]|=(1<<(j&31));
   		}
  	}
	scanf("%s",s); m=strlen(s);
	for(int i=0;i<32;++i)
    	for(int j=0;i+j<m;++j)
      		if(s[i+j]=='1')
				b[i][j>>5]|=(1<<(j&31));

	scanf("%d",&q);
	while(q--){
		scanf("%d %d %d",&p1,&p2,&len);
		printf("%d\n",get(p1,p2,len));
	}
	return 0;
}