#include <bits/stdc++.h>
using namespace std;
int lenA, lenB, q;
char A[400005], B[400005];
int difference[500][500], beginsA[400005], beginsB[400005];
int bucataA[500], bucataB[500], bits[65535 + 1], ans[400005];
unsigned long long configurationA[400005], configurationB[400005];
vector<pair<pair<int, int>, pair<int, int>>> Q[500];
inline int NR_BITS(const long long &x) {
  return bits[x & 65535] + bits[(x >> 16) & 65535] + bits[(x >> 32) & 65535] +
         bits[(x >> 48) & 65535];
}
inline int get_difference(int x, int y, const int &len_bucket) {
  int diff = 0;
  for (int step = 0; step < len_bucket; step += 64) {
    long long a = configurationA[x + step];
    if (step + 64 >= len_bucket) {
      a = configurationA[x + step] >>
          min(lenA - x - len_bucket, (step + 64 - len_bucket));
    }
    long long b = configurationB[y + step];
    if (step + 64 >= len_bucket) {
      b = configurationB[y + step] >>
          min(lenB - y - len_bucket, (step + 64 - len_bucket));
    }
    diff += NR_BITS(a ^ b);
  }
  return diff;
}
int main() {
  for (int i = 1; i <= 65535; ++i) {
    int conf = i;
    while (conf) {
      ++bits[i];
      conf &= (conf - 1);
    }
  }
  scanf("%s%s", A, B);
  lenA = strlen(A), lenB = strlen(B);
  for (int i = lenA - 1; i >= 0; --i) {
    if (lenA - i <= 64) {
      configurationA[i] =
          configurationA[i + 1] + (A[i] == '1' ? 1LL << (lenA - i - 1) : 0);
    } else {
      configurationA[i] =
          (configurationA[i + 1] >> 1) + (A[i] == '1' ? 1LL << 63 : 0);
    }
  }
  for (int i = lenB - 1; i >= 0; --i) {
    if (lenB - i <= 64) {
      configurationB[i] =
          configurationB[i + 1] + (B[i] == '1' ? 1LL << (lenB - i - 1) : 0);
    } else {
      configurationB[i] =
          (configurationB[i + 1] >> 1) + (B[i] == '1' ? 1LL << 63 : 0);
    }
  }
  int len_bucket = 1;
  int max_len = max(lenA, lenB);
  while (len_bucket * len_bucket < max_len) {
    ++len_bucket;
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int x, y, l;
    scanf("%d %d %d", &x, &y, &l);
    int bucket = y - x;
    while (bucket < 0) {
      bucket += len_bucket;
    }
    Q[bucket % len_bucket].push_back(
        make_pair(make_pair(l, i), make_pair(x, y)));
  }
  int last = 0;
  bucataA[++bucataA[0]] = 0;
  beginsA[0] = 1;
  while (last + len_bucket < lenA) {
    last += len_bucket;
    bucataA[++bucataA[0]] = last;
    beginsA[last] = bucataA[0];
  }
  bucataA[bucataA[0] + 1] = lenA;
  for (int start = 0; start < len_bucket; ++start) {
    for (int i = 1; i <= bucataB[0]; ++i) {
      beginsB[bucataB[i]] = 0;
    }
    bucataB[0] = 0;
    last = start;
    bucataB[++bucataB[0]] = last;
    beginsB[start] = 1;
    while (last + len_bucket < lenB) {
      last += len_bucket;
      bucataB[++bucataB[0]] = last;
      beginsB[last] = bucataB[0];
    }
    bucataB[bucataB[0] + 1] = lenB;
    for (int i = 1; i <= bucataA[0]; ++i) {
      for (int j = 1; j <= bucataB[0]; ++j) {
        difference[i][j] = get_difference(bucataA[i], bucataB[j], len_bucket);
      }
    }
    for (pair<pair<int, int>, pair<int, int>> &q : Q[start]) {
      int len = q.first.first, ind = q.first.second, startA = q.second.first,
          startB = q.second.second;
      int sol = 0;
      for (int i = 0; i < len; ++i) {
        if (beginsA[i + startA] && beginsB[i + startB] &&
            i + len_bucket <= len) {
          sol += difference[beginsA[i + startA]][beginsB[i + startB]];
          i += len_bucket - 1;
        } else {
          sol += (A[startA + i] != B[startB + i]);
        }
      }
      ans[ind] = sol;
    }
  }
  for (int i = 1; i <= q; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
