#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("predictive-commoning")
using namespace std;
int bitCount[1 << 16];
const int LEN = (200000 + 31) / 32;
const int MASK = (1 << 16) - 1;
int A[32][LEN];
int B[32][LEN];
int main() {
  ios_base::sync_with_stdio(false);
  bitCount[0] = 0;
  for (int i = 1; i < (1 << 16); ++i) {
    bitCount[i] = bitCount[i >> 1] + (i & 1);
  }
  string a;
  a.reserve(200001);
  cin >> a;
  string b;
  b.reserve(200001);
  cin >> b;
  for (int i = 0; i < 32; ++i) {
    for (int j = 0; i + j < a.size(); ++j) {
      int x = a[i + j] - '0';
      A[i][j >> 5] |= x << (j & 31);
    }
    for (int j = 0; i + j < b.size(); ++j) {
      int x = b[i + j] - '0';
      B[i][j >> 5] |= x << (j & 31);
    }
  }
  int q;
  cin >> q;
  for (int qq = 0; qq < q; ++qq) {
    int p1, p2, len;
    cin >> p1 >> p2 >> len;
    int* AA = A[p1 & 31] + (p1 >> 5);
    int* BB = B[p2 & 31] + (p2 >> 5);
    int nBlocks = len >> 5;
    int ans = 0;
    for (int i = 0; i < nBlocks; ++i) {
      int x = AA[i] ^ BB[i];
      ans += bitCount[x & MASK] + bitCount[(x >> 16) & MASK];
    }
    int left = len & 31;
    if (left) {
      int x = (AA[nBlocks] ^ BB[nBlocks]) & ((1 << left) - 1);
      ans += bitCount[x & MASK] + bitCount[(x >> 16) & MASK];
    }
    cout << ans << endl;
  }
  return 0;
}
