Problem: There is a simple way to create hard tasks: take one simple problem as the query, and try to find an algorithm that can solve it faster than bruteforce. This kind of tasks usually appears in OI contest, and usually involves data structures.

Let's try to create a task, for example, we take the "Hamming distance problem": for two binary strings s and t with the same length, the Hamming distance between them is the number of positions at which the corresponding symbols are different. For example, the Hamming distance between "00111" and "10101" is 2 (the different symbols are marked with bold).

We use the Hamming distance problem as a query in the following way: you are given two strings a and b and several queries. Each query will be: what is the Hamming distance between two strings ap1ap1 + 1...ap1 + len - 1 and bp2bp2 + 1...bp2 + len - 1?

Note, that in this problem the strings are zero-based, that is s = s0s1... s|s| - 1.

Input

The first line contains a string a (1 ≤ |a| ≤ 200000). The second line contains a string b (1 ≤ |b| ≤ 200000). Each character of both strings is either "0" or "1".

The third line contains an integer q (1 ≤ q ≤ 400000) — the number of queries. Each of the following q lines contains three integers: p1, p2 and len (0 ≤ p1 ≤ |a| - len; 0 ≤ p2 ≤ |b| - len), these numbers denote the parameters of the current query.

Output

Output q integers — the answers for the queries.

Examples

Input

101010
11110000
3
0 0 3
2 3 4
5 7 1


Output

1
1
0


Input

10001010101011001010100101010011010
101010100101001010100100101010
5
0 0 12
3 9 7
6 4 15
12 15 10
13 3 20


Output

5
4
3
5
13

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using std::bitset;
using std::cerr;
using std::cin;
using std::complex;
using std::cout;
using std::deque;
using std::endl;
using std::ios_base;
using std::iterator;
using std::map;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::multimap;
using std::multiset;
using std::pair;
using std::queue;
using std::reverse;
using std::set;
using std::sort;
using std::stable_sort;
using std::stack;
using std::string;
using std::swap;
using std::unique;
using std::vector;
namespace MySpace {
struct Small_Segment_Tree {
  vector<int> a;
  int l, r;

 private:
  int __summ(int L, int R, int l, int r, int v) {
    if (L <= l && r <= R) return a[v];
    if (R <= l || r <= L) return 0;
    int m = (l + r) / 2;
    return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2);
  }
  void __set(int P, int l, int r, int v, int V) {
    if (l + 1 == r) {
      a[v] = V;
      return;
    }
    int m = (l + r) / 2;
    if (P < m) {
      __set(P, l, m, 2 * v + 1, V);
      a[v] = a[2 * v + 1] + a[2 * v + 2];
    } else {
      __set(P, m, r, 2 * v + 2, V);
      a[v] = a[2 * v + 1] + a[2 * v + 2];
    }
  }

 public:
  int Summ(int L, int R) {
    if (R < L) return 0;
    return __summ(L, R + 1, l, r, 0);
  }
  void Set(int P, int V) { __set(P, l, r, 0, V); }
  Small_Segment_Tree(int _n) {
    a.resize(4 * _n);
    l = 0, r = _n;
  }
};
long long inq(long long x, long long q, long long MOD) {
  if (q == 0) return 1;
  long long l = inq(x, q / 2, MOD);
  if (q % 2) return l * l % MOD * x % MOD;
  return l * l % MOD;
}
};  // namespace MySpace
using namespace MySpace;
const long long MOD = 1e9 + 7;
const int LG = 18;
const int SZ = (1 << LG);
const int K = 6000;
const int N = 2e5 + 10;
const double PI = atan2(0, -1);
int bitreverse[SZ + 1];
int ans[N / K + 1][N];
string A, B;
int BitReverse(int x) {
  int y = 0;
  for (int i = 0; i < LG; i++) {
    y = 2 * y + ((x & (1 << i)) > 0);
  }
  return y;
}
inline complex<double> rev(complex<double> x) {
  x.imag(-x.imag());
  return x;
}
inline pair<vector<complex<double> >, vector<complex<double> > > dftAB(
    vector<int> a, vector<int> b) {
  vector<complex<double> > d(SZ);
  for (int i = 0; i < SZ; i++) {
    d[i].real(a[bitreverse[i]]);
    d[i].imag(b[bitreverse[i]]);
  }
  for (int len = 2; len <= SZ; len += len) {
    double ang = 2 * PI / len;
    complex<double> wlen(cos(ang), sin(ang));
    for (int i = 0; i < SZ; i += len) {
      complex<double> w(1, 0);
      for (int j = 0; j < len / 2; j++) {
        complex<double> u = d[i + j], v = d[i + j + len / 2] * w;
        d[i + j] = u + v;
        d[i + j + len / 2] = u - v;
        w = w * wlen;
      }
    }
  }
  vector<complex<double> > e(SZ), f(SZ);
  complex<double> two(2, 0), ione(0, 1);
  for (int i = 0; i < SZ; i++) {
    e[i] = (d[i] + rev(d[(SZ - i) % SZ])) / two;
    f[i] = (d[i] - rev(d[(SZ - i) % SZ])) / (two * ione);
  }
  return {e, f};
}
inline vector<complex<double> > dft(vector<complex<double> >& a, int fl) {
  vector<complex<double> > b(SZ);
  for (int i = 0; i < SZ; i++) {
    b[i] = a[bitreverse[i]];
  }
  for (int len = 2; len <= SZ; len += len) {
    double ang = 2 * PI / len * fl;
    complex<double> wlen(cos(ang), sin(ang));
    for (int i = 0; i < SZ; i += len) {
      complex<double> w(1, 0);
      for (int j = 0; j < len / 2; j++) {
        complex<double> u = b[i + j], v = b[i + j + len / 2] * w;
        b[i + j] = u + v;
        b[i + j + len / 2] = u - v;
        w = w * wlen;
      }
    }
  }
  return b;
}
inline void fft(vector<int>& a0, vector<int>& b0, int where) {
  vector<int> a(SZ), b(SZ);
  vector<complex<double> > c(SZ);
  for (int i = 0; i < a.size(); i++)
    if (i < a0.size()) a[i] = a0[i];
  for (int i = 0; i < b.size(); i++)
    if (i < b0.size()) b[i] = b0[i];
  pair<vector<complex<double> >, vector<complex<double> > > ab = dftAB(a, b);
  for (int i = 0; i < c.size(); i++) c[i] = ab.first[i] * ab.second[i];
  c = dft(c, -1);
  long long expected = K;
  for (int i = 0; i < A.size(); i++) {
    ans[where][i] = (K - round(c[K - 1 + i].real() / SZ)) / 2;
  }
}
long long Lrunned[N];
long long Rrunned[N];
signed main() {
  for (int i = 0; i < SZ; i++) bitreverse[i] = BitReverse(i);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> A >> B;
  vector<int> a, b;
  for (int i = 0; i < A.size(); i++)
    if (A[i] == '1')
      a.push_back(1);
    else
      a.push_back(-1);
  for (int i = 0; i + K <= B.size(); i += K) {
    Lrunned[i] = 1;
    Rrunned[i + K - 1] = 1;
    b.resize(0);
    for (int j = i + K - 1; j >= i; j--)
      if (B[j] == '1')
        b.push_back(1);
      else
        b.push_back(-1);
    while (b.size() < SZ) b.push_back(0);
    fft(a, b, i / K);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int p1, p2, len;
    cin >> p1 >> p2 >> len;
    int q1 = p1 + len - 1;
    int q2 = p2 + len - 1;
    int answ = 0;
    while (p2 <= q2 && Lrunned[p2] == 0) {
      answ += (A[p1] != B[p2]);
      p1++;
      p2++;
    }
    while (q2 >= p2 && Rrunned[q2] == 0) {
      answ += (A[q1] != B[q2]);
      q1--;
      q2--;
    }
    while (p2 <= q2) {
      answ += ans[p2 / K][p1];
      p1 += K;
      p2 += K;
    }
    cout << answ << "\n";
  }
}