import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct ModInt(int M_) {
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}

enum MO = 10^^9 + 403;
alias Mint = ModInt!MO;
Mint R = 2020;

// T: monoid
// op: T * T -> T
// query(a, b): returns t_a ... t_{b-1}
class SegmentTree(T, alias op) {
  import std.functional : binaryFun;
  alias opFun = binaryFun!op;
  const(T) idT;

  int n;
  T[] ts;
  this(int n_, const(T) idT) {
    this.idT = idT;
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[] = idT;
  }
  this(inout(T)[] ts_, const(T) idT) {
    this.idT = idT;
    const n_ = cast(int)(ts_.length);
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[0 .. n] = idT;
    ts[n .. n + n_] = ts_[];
    ts[n + n_ .. n << 1] = idT;
    build();
  }
  ref T at(int a) {
    return ts[n + a];
  }
  void build() {
    foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void set(int a, const(T) val) {
    ts[a += n] = val;
    for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void mulL(int a, const(T) val) {
    set(a, opFun(val, ts[a + n]));
  }
  void mulR(int a, const(T) val) {
    set(a, opFun(ts[a + n], val));
  }
  T query(int a, int b) const {
    T prodL = idT, prodR = idT;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) prodL = opFun(prodL, ts[a++]);
      if (b & 1) prodR = opFun(ts[--b], prodR);
    }
    return opFun(prodL, prodR);
  }
}

Mint[] RR;

struct Info {
  int num1, len, head;
  Mint val;
  Info opBinary(string op)(const(Info) o) const if (op == "*") {
    Info ret;
    ret.num1 = num1 + o.num1;
    if (len == 0) {
      ret.len = o.len;
      ret.head = (num1 & 1) ^ o.head;
      ret.val = o.val;
    } else if (o.len == 0) {
      ret.len = len;
      ret.head = head;
      ret.val = val;
    } else if ((head ^ (len & 1)) == ((num1 & 1) ^ o.head)) {
      // concat
      ret.len = len + o.len;
      ret.head = head;
      ret.val = val + RR[len] * o.val;
    } else {
      // overlap
      ret.len = len + o.len - 1;
      ret.head = head;
      ret.val = val + RR[len - 1] * o.val;
    }
    return ret;
  }
}

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const T = readToken();
      const Q = readInt();
      auto A = new int[Q];
      auto B = new int[Q];
      auto L = new int[Q];
      foreach (q; 0 .. Q) {
        A[q] = readInt() - 1;
        B[q] = readInt() - 1;
        L[q] = readInt();
      }

      foreach (q; 0 .. Q) {
        R.x ^= A[q] ^ B[q] ^ L[q];
      }
      RR = new Mint[N + 1];
      RR[0] = 1;
      foreach (i; 1 .. N + 1) {
        RR[i] = RR[i - 1] * R;
      }

      auto seg = new SegmentTree!(Info, "a * b")(N, Info(0, 0, 0, Mint(0)));
      foreach (i; 0 .. N) {
        seg.at(i) = (T[i] == '1') ? Info(1, 0, 0, Mint(0)) : Info(0, 1, 0, Mint(1));
      }
      seg.build;
      debug {
        foreach (i; 0 .. N) foreach (j; i + 1 .. N + 1) {
          // writeln(i, " ", j, ": ", seg.query(i, j));
        }
      }

      foreach (q; 0 .. Q) {
        const resA = seg.query(A[q], A[q] + L[q]);
        const resB = seg.query(B[q], B[q] + L[q]);
        debug {
          writeln(true, " ", resA, " ", resB);
        }
        const ans = (resA == resB);
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct ModInt(int M_) {
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}

enum MO = 10^^9 + 403;
alias Mint = ModInt!MO;

// T: monoid
// op: T * T -> T
// query(a, b): returns t_a ... t_{b-1}
class SegmentTree(T, alias op) {
  import std.functional : binaryFun;
  alias opFun = binaryFun!op;
  const(T) idT;

  int n;
  T[] ts;
  this(int n_, const(T) idT) {
    this.idT = idT;
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[] = idT;
  }
  this(inout(T)[] ts_, const(T) idT) {
    this.idT = idT;
    const n_ = cast(int)(ts_.length);
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[0 .. n] = idT;
    ts[n .. n + n_] = ts_[];
    ts[n + n_ .. n << 1] = idT;
    build();
  }
  ref T at(int a) {
    return ts[n + a];
  }
  void build() {
    foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void set(int a, const(T) val) {
    ts[a += n] = val;
    for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void mulL(int a, const(T) val) {
    set(a, opFun(val, ts[a + n]));
  }
  void mulR(int a, const(T) val) {
    set(a, opFun(ts[a + n], val));
  }
  T query(int a, int b) const {
    T prodL = idT, prodR = idT;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) prodL = opFun(prodL, ts[a++]);
      if (b & 1) prodR = opFun(ts[--b], prodR);
    }
    return opFun(prodL, prodR);
  }
}

Mint R;
Mint[] RR;

struct Info {
  int num1, len, head;
  Mint val;
  Info opBinary(string op)(const(Info) o) const if (op == "*") {
    Info ret;
    ret.num1 = num1 + o.num1;
    if (len == 0) {
      ret.len = o.len;
      ret.head = (num1 & 1) ^ o.head;
      ret.val = o.val;
    } else if (o.len == 0) {
      ret.len = len;
      ret.head = head;
      ret.val = val;
    } else if ((head ^ (len & 1)) == ((num1 & 1) ^ o.head)) {
      // concat
      ret.len = len + o.len;
      ret.head = head;
      ret.val = val + RR[len] * o.val;
    } else {
      // overlap
      ret.len = len + o.len - 1;
      ret.head = head;
      ret.val = val + RR[len - 1] * o.val;
    }
    return ret;
  }
}

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const T = readToken();
      const Q = readInt();
      auto A = new int[Q];
      auto B = new int[Q];
      auto L = new int[Q];
      foreach (q; 0 .. Q) {
        A[q] = readInt() - 1;
        B[q] = readInt() - 1;
        L[q] = readInt();
      }

      import std.datetime;
      R = 2020 ^ Clock.currStdTime;
      debug {
        writeln("R = ", R);
      }
      RR = new Mint[N + 1];
      RR[0] = 1;
      foreach (i; 1 .. N + 1) {
        RR[i] = RR[i - 1] * R;
      }

      auto seg = new SegmentTree!(Info, "a * b")(N, Info(0, 0, 0, Mint(0)));
      foreach (i; 0 .. N) {
        seg.at(i) = (T[i] == '1') ? Info(1, 0, 0, Mint(0)) : Info(0, 1, 0, Mint(1));
      }
      seg.build;
      debug {
        foreach (i; 0 .. N) foreach (j; i + 1 .. N + 1) {
          // writeln(i, " ", j, ": ", seg.query(i, j));
        }
      }

      foreach (q; 0 .. Q) {
        const resA = seg.query(A[q], A[q] + L[q]);
        const resB = seg.query(B[q], B[q] + L[q]);
        debug {
          writeln(true, " ", resA, " ", resB);
        }
        const ans = (resA == resB);
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct SuffixArray(T) {
  import std.algorithm : sort;
  int n;
  T[] ts;
  int[] us, su, lcp;
  this(T)(T[] ts) {
    n = cast(int)(ts.length);
    this.ts = ts;
    us = new int[n + 1];
    su = new int[n + 1];
    foreach (i; 0 .. n + 1) us[i] = i;
    us.sort!((u, v) => (cmp(u, v) < 0));
    auto vals = new int[n + 1], cnt = new int[n + 1], tmp = new int[n + 1];
    foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((cmp(us[i], us[i + 1]) < 0) ? 1 : 0);
    for (int h = 1; ; h <<= 1) {
      int ahead(int i) {
        return (us[i] + h <= n) ? su[us[i] + h] : 0;
      }
      foreach (i; 0 .. n + 1) su[us[i]] = vals[i];
      if (vals[n] == n) break;
      cnt[] = 0;
      foreach (i; 0 .. n + 1) ++cnt[ahead(i)];
      foreach (j; 0 .. n) cnt[j + 1] += cnt[j];
      foreach_reverse (i; 0 .. n + 1) tmp[--cnt[ahead(i)]] = us[i];
      cnt[] = 0;
      foreach (i; 0 .. n + 1) ++cnt[su[tmp[i]]];
      foreach (j; 0 .. n) cnt[j + 1] += cnt[j];
      foreach_reverse (i; 0 .. n + 1) us[--cnt[su[tmp[i]]]] = tmp[i];
      foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((su[us[i]] < su[us[i + 1]] || ahead(i) < ahead(i + 1)) ? 1 : 0);
    }
    lcp = new int[n];
    int h;
    foreach (u; 0 .. n) {
      for (int v = us[su[u] - 1]; cmp(u + h, v + h) == 0; ++h) {}
      lcp[su[u] - 1] = h;
      if (h > 0) --h;
    }
  }
  int cmp(int u, int v) const {
    return (u == n) ? ((v == n) ? 0 : -1) : (v == n) ? +1 : (ts[u] < ts[v]) ? -1 : (ts[u] > ts[v]) ? +1 : 0;
  }
  void print() const {
    import std.math : log10;
    import std.stdio : writefln;
    const numDigits = cast(int)(log10(n)) + 1;
    foreach (i; 0 .. n + 1) {
      writefln("%*d %s", numDigits, us[i], ts[us[i] .. $]);
    }
  }
}

// T: monoid
// op: T * T -> T
// query(a, b): returns t_a ... t_{b-1}
class SegmentTree(T, alias op) {
  import std.functional : binaryFun;
  alias opFun = binaryFun!op;
  const(T) idT;

  int n;
  T[] ts;
  this(int n_, const(T) idT) {
    this.idT = idT;
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[] = idT;
  }
  this(inout(T)[] ts_, const(T) idT) {
    this.idT = idT;
    const n_ = cast(int)(ts_.length);
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[0 .. n] = idT;
    ts[n .. n + n_] = ts_[];
    ts[n + n_ .. n << 1] = idT;
    build();
  }
  ref T at(int a) {
    return ts[n + a];
  }
  void build() {
    foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void set(int a, const(T) val) {
    ts[a += n] = val;
    for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void mulL(int a, const(T) val) {
    set(a, opFun(val, ts[a + n]));
  }
  void mulR(int a, const(T) val) {
    set(a, opFun(ts[a + n], val));
  }
  T query(int a, int b) const {
    T prodL = idT, prodR = idT;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) prodL = opFun(prodL, ts[a++]);
      if (b & 1) prodR = opFun(ts[--b], prodR);
    }
    return opFun(prodL, prodR);
  }
}

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const T = readToken();
      const Q = readInt();
      auto A = new int[Q];
      auto B = new int[Q];
      auto L = new int[Q];
      foreach (q; 0 .. Q) {
        A[q] = readInt() - 1;
        B[q] = readInt() - 1;
        L[q] = readInt();
      }

      auto num1 = new int[N + 1];
      foreach (i; 0 .. N) {
        num1[i + 1] = num1[i] + ((T[i] == '1') ? 1 : 0);
      }
      auto num11 = new int[N];
      foreach (i; 0 .. N - 1) {
        num11[i + 1] = num11[i] + ((T[i] == '1' && T[i + 1] == '1') ? 1 : 0);
      }

      auto sum = new long[N + 1];
      foreach (i; 0 .. N) {
        sum[i + 1] = sum[i] + ((T[i] == '1') ? i : 0);
      }

      auto sa = new SuffixArray!(immutable(char))(T);
      auto seg = new SegmentTree!(int, min)(sa.lcp, N + 1);

      foreach (q; 0 .. Q) {
        bool ans;
        if (num11[A[q] + L[q] - 1] - num11[A[q]] > 0 && num11[B[q] + L[q] - 1] - num11[B[q]] > 0) {
          const n1A = num1[A[q] + L[q]] - num1[A[q]];
          const n1B = num1[B[q] + L[q]] - num1[B[q]];
          const sA = (sum[A[q] + L[q]] - sum[A[q]]) - 1L * n1A * A[q];
          const sB = (sum[B[q] + L[q]] - sum[B[q]]) - 1L * n1B * B[q];
          debug {
            writeln(true, " ", [n1A, n1B], " ", [sA, sB]);
          }
          ans = (n1A == n1B && (sA - sB) % 2 == 0);
        } else {
          int a = sa.su[A[q]], b = sa.su[B[q]];
          if (a > b) {
            swap(a, b);
          }
          const res = seg.query(a, b);
          debug {
            writeln(false, " ", A[q], " ", B[q], ": ", res);
          }
          ans = (res >= L[q]);
        }
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct SuffixArray(T) {
  import std.algorithm : sort;
  int n;
  T[] ts;
  int[] us, su, lcp;
  this(T)(T[] ts) {
    n = cast(int)(ts.length);
    this.ts = ts;
    us = new int[n + 1];
    su = new int[n + 1];
    foreach (i; 0 .. n + 1) us[i] = i;
    us.sort!((u, v) => (cmp(u, v) < 0));
    auto vals = new int[n + 1], cnt = new int[n + 1], tmp = new int[n + 1];
    foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((cmp(us[i], us[i + 1]) < 0) ? 1 : 0);
    for (int h = 1; ; h <<= 1) {
      int ahead(int i) {
        return (us[i] + h <= n) ? su[us[i] + h] : 0;
      }
      foreach (i; 0 .. n + 1) su[us[i]] = vals[i];
      if (vals[n] == n) break;
      cnt[] = 0;
      foreach (i; 0 .. n + 1) ++cnt[ahead(i)];
      foreach (j; 0 .. n) cnt[j + 1] += cnt[j];
      foreach_reverse (i; 0 .. n + 1) tmp[--cnt[ahead(i)]] = us[i];
      cnt[] = 0;
      foreach (i; 0 .. n + 1) ++cnt[su[tmp[i]]];
      foreach (j; 0 .. n) cnt[j + 1] += cnt[j];
      foreach_reverse (i; 0 .. n + 1) us[--cnt[su[tmp[i]]]] = tmp[i];
      foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((su[us[i]] < su[us[i + 1]] || ahead(i) < ahead(i + 1)) ? 1 : 0);
    }
    lcp = new int[n];
    int h;
    foreach (u; 0 .. n) {
      for (int v = us[su[u] - 1]; cmp(u + h, v + h) == 0; ++h) {}
      lcp[su[u] - 1] = h;
      if (h > 0) --h;
    }
  }
  int cmp(int u, int v) const {
    return (u == n) ? ((v == n) ? 0 : -1) : (v == n) ? +1 : (ts[u] < ts[v]) ? -1 : (ts[u] > ts[v]) ? +1 : 0;
  }
  void print() const {
    import std.math : log10;
    import std.stdio : writefln;
    const numDigits = cast(int)(log10(n)) + 1;
    foreach (i; 0 .. n + 1) {
      writefln("%*d %s", numDigits, us[i], ts[us[i] .. $]);
    }
  }
}

// T: monoid
// op: T * T -> T
// query(a, b): returns t_a ... t_{b-1}
class SegmentTree(T, alias op) {
  import std.functional : binaryFun;
  alias opFun = binaryFun!op;
  const(T) idT;

  int n;
  T[] ts;
  this(int n_, const(T) idT) {
    this.idT = idT;
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[] = idT;
  }
  this(inout(T)[] ts_, const(T) idT) {
    this.idT = idT;
    const n_ = cast(int)(ts_.length);
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[0 .. n] = idT;
    ts[n .. n + n_] = ts_[];
    ts[n + n_ .. n << 1] = idT;
    build();
  }
  ref T at(int a) {
    return ts[n + a];
  }
  void build() {
    foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void set(int a, const(T) val) {
    ts[a += n] = val;
    for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void mulL(int a, const(T) val) {
    set(a, opFun(val, ts[a + n]));
  }
  void mulR(int a, const(T) val) {
    set(a, opFun(ts[a + n], val));
  }
  T query(int a, int b) const {
    T prodL = idT, prodR = idT;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) prodL = opFun(prodL, ts[a++]);
      if (b & 1) prodR = opFun(ts[--b], prodR);
    }
    return opFun(prodL, prodR);
  }
}

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const T = readToken();
      const Q = readInt();
      auto A = new int[Q];
      auto B = new int[Q];
      auto L = new int[Q];
      foreach (q; 0 .. Q) {
        A[q] = readInt() - 1;
        B[q] = readInt() - 1;
        L[q] = readInt();
      }

      auto num1 = new int[N + 1];
      foreach (i; 0 .. N) {
        num1[i + 1] = num1[i] + ((T[i] == '1') ? 1 : 0);
      }
      auto num11 = new int[N];
      foreach (i; 0 .. N - 1) {
        num11[i + 1] = num11[i] + ((T[i] == '1' && T[i + 1] == '1') ? 1 : 0);
      }

      auto sa = new SuffixArray!(immutable(char))(T);
      auto seg = new SegmentTree!(int, min)(sa.lcp, N + 1);

      foreach (q; 0 .. Q) {
        bool ans;
        if (num11[A[q] + L[q] - 1] - num11[A[q]] > 0 && num11[B[q] + L[q] - 1] - num11[B[q]] > 0) {
          ans = (num1[A[q] + L[q]] - num1[A[q]] == num1[B[q] + L[q]] - num1[B[q]]);
        } else {
          int a = sa.su[A[q]], b = sa.su[B[q]];
          if (a > b) {
            swap(a, b);
          }
          const res = seg.query(a, b);
          debug {
            writeln(A[q], " ", B[q], ": ", res);
          }
          ans = (res >= L[q]);
        }
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct SuffixArray(T) {
  import std.algorithm : sort;
  int n;
  T[] ts;
  int[] us, su, lcp;
  this(T)(T[] ts) {
    n = cast(int)(ts.length);
    this.ts = ts;
    us = new int[n + 1];
    su = new int[n + 1];
    foreach (i; 0 .. n + 1) us[i] = i;
    us.sort!((u, v) => (cmp(u, v) < 0));
    auto vals = new int[n + 1], cnt = new int[n + 1], tmp = new int[n + 1];
    foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((cmp(us[i], us[i + 1]) < 0) ? 1 : 0);
    for (int h = 1; ; h <<= 1) {
      int ahead(int i) {
        return (us[i] + h <= n) ? su[us[i] + h] : 0;
      }
      foreach (i; 0 .. n + 1) su[us[i]] = vals[i];
      if (vals[n] == n) break;
      cnt[] = 0;
      foreach (i; 0 .. n + 1) ++cnt[ahead(i)];
      foreach (j; 0 .. n) cnt[j + 1] += cnt[j];
      foreach_reverse (i; 0 .. n + 1) tmp[--cnt[ahead(i)]] = us[i];
      cnt[] = 0;
      foreach (i; 0 .. n + 1) ++cnt[su[tmp[i]]];
      foreach (j; 0 .. n) cnt[j + 1] += cnt[j];
      foreach_reverse (i; 0 .. n + 1) us[--cnt[su[tmp[i]]]] = tmp[i];
      foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((su[us[i]] < su[us[i + 1]] || ahead(i) < ahead(i + 1)) ? 1 : 0);
    }
    lcp = new int[n];
    int h;
    foreach (u; 0 .. n) {
      for (int v = us[su[u] - 1]; cmp(u + h, v + h) == 0; ++h) {}
      lcp[su[u] - 1] = h;
      if (h > 0) --h;
    }
  }
  int cmp(int u, int v) const {
    return (u == n) ? ((v == n) ? 0 : -1) : (v == n) ? +1 : (ts[u] < ts[v]) ? -1 : (ts[u] > ts[v]) ? +1 : 0;
  }
  void print() const {
    import std.math : log10;
    import std.stdio : writefln;
    const numDigits = cast(int)(log10(n)) + 1;
    foreach (i; 0 .. n + 1) {
      writefln("%*d %s", numDigits, us[i], ts[us[i] .. $]);
    }
  }
}

// T: monoid
// op: T * T -> T
// query(a, b): returns t_a ... t_{b-1}
class SegmentTree(T, alias op) {
  import std.functional : binaryFun;
  alias opFun = binaryFun!op;
  const(T) idT;

  int n;
  T[] ts;
  this(int n_, const(T) idT) {
    this.idT = idT;
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[] = idT;
  }
  this(inout(T)[] ts_, const(T) idT) {
    this.idT = idT;
    const n_ = cast(int)(ts_.length);
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ts[0 .. n] = idT;
    ts[n .. n + n_] = ts_[];
    ts[n + n_ .. n << 1] = idT;
    build();
  }
  ref T at(int a) {
    return ts[n + a];
  }
  void build() {
    foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void set(int a, const(T) val) {
    ts[a += n] = val;
    for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);
  }
  void mulL(int a, const(T) val) {
    set(a, opFun(val, ts[a + n]));
  }
  void mulR(int a, const(T) val) {
    set(a, opFun(ts[a + n], val));
  }
  T query(int a, int b) const {
    T prodL = idT, prodR = idT;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) prodL = opFun(prodL, ts[a++]);
      if (b & 1) prodR = opFun(ts[--b], prodR);
    }
    return opFun(prodL, prodR);
  }
}

struct Info {
  int a, b0, b1;
  Info opBinary(string op)(const(Info) o) const if (op == "*") {
    return Info(a + o.a, b0 + ((a & 1) ? o.b1 : o.b0), b1 + ((a & 1) ? o.b0 : o.b1));
  }
}

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const T = readToken();
      const Q = readInt();
      auto A = new int[Q];
      auto B = new int[Q];
      auto L = new int[Q];
      foreach (q; 0 .. Q) {
        A[q] = readInt() - 1;
        B[q] = readInt() - 1;
        L[q] = readInt();
      }

      auto num1 = new int[N + 1];
      foreach (i; 0 .. N) {
        num1[i + 1] = num1[i] + ((T[i] == '1') ? 1 : 0);
      }
      auto num11 = new int[N];
      foreach (i; 0 .. N - 1) {
        num11[i + 1] = num11[i] + ((T[i] == '1' && T[i + 1] == '1') ? 1 : 0);
      }

      auto segInfo = new SegmentTree!(Info, "a * b")(N, Info(0, 0, 0));
      foreach (i; 0 .. N) {
        segInfo.at(i) = (T[i] == '1') ? Info(1, 0, 0) : Info(0, 1, 0);
      }
      segInfo.build;
      debug {
        foreach (i; 0 .. N) foreach (j; i + 1 .. N + 1) {
          // writeln(i, " ", j, ": ", segInfo.query(i, j));
        }
      }

      auto sa = new SuffixArray!(immutable(char))(T);
      auto segLCP = new SegmentTree!(int, min)(sa.lcp, N + 1);

      foreach (q; 0 .. Q) {
        bool ans;
        if (num11[A[q] + L[q] - 1] - num11[A[q]] > 0 && num11[B[q] + L[q] - 1] - num11[B[q]] > 0) {
          const resA = segInfo.query(A[q], A[q] + L[q]);
          const resB = segInfo.query(B[q], B[q] + L[q]);
          debug {
            writeln(true, " ", resA, " ", resB);
          }
          ans = (resA == resB);
        } else {
          int a = sa.su[A[q]], b = sa.su[B[q]];
          if (a > b) {
            swap(a, b);
          }
          const res = segLCP.query(a, b);
          debug {
            writeln(false, " ", A[q], " ", B[q], ": ", res);
          }
          ans = (res >= L[q]);
        }
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}


import core.bitop, std.bitmanip;
import std.algorithm, std.functional;
import std.array, std.container;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

immutable int INF = 10L ^^ 9 + 23;
immutable int N = 10 ^^ 6 + 23;

int[N] fw;

void fwadd(int p, int x) {
    while (p < N) {
        fw[p] += x;
        p += (1 << bsf(p));
    }
}

int fwsum(int p) {
    int ans = 0;
    while (p > 0) {
        ans += fw[p];
        p -= (1 << bsf(p));
    }

    debug { ans.writeln; }

    return ans;
}

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    bool odd = false;
    foreach_reverse (e; arr) {
        odd ^= fwsum(e) & 1;
        fwadd(e, 1);
    }

    debug { odd.writeln; }

    bool PetrOdd = (3 * n) & 1;

    writeln(odd == PetrOdd ? "Petr" : "Um_nik");
}

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  debug dbg ();
  readf (" %d", &n);
  auto a = new int[n];
  foreach (i; 0 .. n) {
    readf (" %d", &a[i]);
  }
  auto b = new int[n];
  int merge (int l, int r) {
    if (r - l > 1) {
      immutable m = (l + r) >> 1;
      int res = merge (l, m) ^ merge (m, r);
      int i = l;
      int j = m;
      int k = 0;
      while (i < m && j < r) {
        if (a[i] < a[j]) {
          b[k++] = a[i++];
        } else {
          b[k++] = a[j++];
          res ^= (m - i) & 1;
        }
      }
      while (i < m) b[k++] = a[i++];
      while (j < r) b[k++] = a[j++];
      assert (r - l == k);
      a[l .. r] = b[0 .. k];
      return res;
    }
    return 0;
  }
  int r = merge (0, n);
  assert (r == 0 || r == 1);
  debug stderr.writeln (r);
  debug stderr.writeln (a);
  writeln (r == ((3 * n) & 1) ? "Petr" : "Um_nik");
}

void dbg () {
  foreach (i; 1000 .. 1000000) {
    assert ( (((3 * i) ^ (7 * i + 1)) & 1) == 1);
  }
}


// Author: Ivan Kazmenko (gassa@mail.ru)
module solution;
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto k = readln.strip;
		auto s = readln.strip;
		auto t = s.map !(x => k.countUntil (x)).array;
		zip (t, t.drop (1)).map !(q{abs (a[0] - a[1])}).sum.writeln;
	}
}

immutable multi = true;

void solve(int tc)
{
	auto alphabet = readString;
	auto word = readString;
	int[char] position;
	foreach(i, ch; alphabet) position[ch] = cast(int)i;
	long sum = 0;
	foreach(i; 1 .. word.length)
	{
		sum += abs(position[word[i]] - position[word[i-1]]);
	}
	sum.writeln;
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
	{
		popChar;
	}
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}


import std.stdio, std.conv, std.string, std.regex;
void main()
{
    string command;
    string[] lexems;
    auto reg = regex("[^\" ]+|(\"[^\"]*\")");

    command = readln();
    command = strip(command);

    while(true)
    {
        auto m = match(command, reg);
        if (m.empty) break;
        lexems ~= chomp(chompPrefix(m.front.hit, `"`),`"`);
        command = m.post;
    }

    foreach(ref l; lexems)
        writeln("<", l, ">");
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	string s;
	while ((s = readln ()) != null)
	{
		while (1)
		{
			s = strip (s);
			if (s.length == 0)
			{
				break;
			}
			string t;
			if (s[0] == '"')
			{
				t = find (s[1..$], '"');
				writefln ("<%s>", s[1..$ - t.length]);
			}
			else
			{
				t = find (s[1..$], ' ');
				writefln ("<%s>", s[0..$ - t.length]);
			}
			s = t;
			if (s.length > 0)
			{
				s = s[1..$];
			}
		}
	}
}

module cf_291B;

import std.stdio;

void main() {
    char symbol;
    bool wasQuote = false;
    string lexem;

    while (readf("%c", &symbol)) {
        if (symbol == '\"') {
            wasQuote = !wasQuote;

            if (!wasQuote) {
                writefln("<%s>", lexem);
            }
            lexem = "";

            continue;
        }

        lexem ~= symbol;
        if (!wasQuote && (symbol == ' ' || symbol == '\n')) {
            lexem = lexem[0 .. $ - 1];
            if (lexem.length > 0) {
                writefln("<%s>", lexem);
                lexem = "";
            }
        }

        if (symbol == '\n') {
            break;
        }
    }
}

module sigod.codeforces.p291B;

import std.array;
import std.stdio;
import std.string;

void main()
{
	auto result = solve(stdin.readln());

	foreach (r; result) {
		stdout.writeln(r);
	}
}

string[] solve(string input)
{
	input = input.strip();

	auto result = appender!(string[])();

	bool quote = false;
	bool without = false;
	int start;

	foreach (index, c; input) {
		if (quote) {
			if (c == '"') {
				result.put('<' ~ input[start + 1 .. index] ~ '>');
				quote = false;
			}
		}
		else if (without) {
			if (c == ' ') {
				result.put('<' ~ input[start .. index] ~ '>');
				without = false;
			}
		}
		else {
			if (c == '"') {
				quote = true;
				start = index;
			}
			else if (c != ' ') {
				without = true;
				start = index;
			}
		}
	}

	if (without) {
		result.put('<' ~ input[start .. $] ~ '>');
	}

	return result.data();
}

unittest {
	assert(std.algorithm.equal(solve(`"RUn.exe O" "" "   2ne, " two! . " "`), [
			"<RUn.exe O>",
			"<>",
			"<   2ne, >",
			"<two!>",
			"<.>",
			"< >"
		]));
	assert(std.algorithm.equal(solve(`   firstarg   second   ""    `), [
			"<firstarg>",
			"<second>",
			"<>"
		]));
}

module cf_291B;

import std.stdio;

void main() {
    char symbol;
    bool wasQuote = false;
    string lexem;

    while (readf("%c", &symbol), symbol != '\n') {
        if (symbol == '\"') {
            wasQuote = !wasQuote;

            if (!wasQuote) {
                writefln("<%s>", lexem);
            }
            lexem = "";

            continue;
        }

        lexem ~= symbol;
        if (!wasQuote && symbol == ' ') {
            lexem = lexem[0 .. $ - 1];
            if (lexem.length > 0) {
                writefln("<%s>", lexem);
                lexem = "";
            }
        }
    }
}


import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!long).array;
        long d = params[2];

        if(params[0] == 0 || params[1] == 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) + (max % min != 0 ? 1 : 0) - 1;
            writeln(res <= d ? "YES" : "NO");
        }
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!long).array;
        long d = params[2];

        if(abs(params[0] - params[1]) <= d)
        {
            writeln("YES");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) + (max % min != 0 ? 1 : 0) - 1;
            writeln(res <= d ? "YES" : "NO");
        }
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto r = RD;
		auto b = RD;
		auto d = RD;

		auto x = min(b, r);
		auto y = max(b, r);
		ans[ti] = y-x <= d * x;
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}

// Vicfred
// https://codeforces.com/contest/1519/problem/A
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;

while(t--) {
    long r, b, d;
    readf("%s %s %s\n", &r, &b, &d);
    if(r > b)
        swap(r,b);
    if(b <= r*(d + 1))
        "YES".writeln;
    else
        "NO".writeln;
}
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!long).array;
        long d = params[2];

        if(params[0] == 0 || params[1] == 0)
        {
            writeln("NO");
        }
        else if(abs(params[0] - params[1]) <= d)
        {
            writeln("YES");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) + (max % min) - 1;
            writeln(res <= d ? "YES" : "NO");
        }
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!long).array;
        long d = params[2];

        if(params[0] <= 0 || params[1] <= 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) + (max % min) - 1;
            writeln(res <= d ? "YES" : "NO");
        }
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!long).array;
        long d = params[2];

        if(params[0] <= 0 || params[1] <= 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) - 1;
            writeln(max % min <= d && res <= d ? "YES" : "NO");
        }
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!long).array;
        long d = params[2];

        if(params[0] <= 0 || params[1] <= 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) - min;
            writeln(res >= 0 && res <= d ? "YES" : "NO");
        }
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!long).array;
        long d = params[2];

        if(params[0] <= 0 || params[1] <= 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];

            writeln(abs((max / min) - min) <= d ? "YES" : "NO");
        }
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!int).array;
        int d = params[2];

        if(params[0] == 0 || params[1] == 0)
        {
            writeln("NO");
        }
        if(params[0] == 1 || params[1] == 1)
        {
            writeln(d == 0 ? "YES" : "NO");
        }
        else
        {
            int min = params[0] > params[1] ? params[1] : params[0];
            int max = params[0] > params[1] ? params[0] : params[1];

            writeln(abs((max / min) - min) <= d ? "YES" : "NO");
        }
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto params = readln().chomp.splitter(" ").map!(to!int).array;
        int d = params[2];

        if(params[0] == 0 || params[1] == 0)
        {
            writeln("NO");
        }
        else
        {
            int min = params[0] > params[1] ? params[1] : params[0];
            int max = params[0] > params[1] ? params[0] : params[1];

            writeln(abs((max / min) - min) <= d ? "YES" : "NO");
        }
    }
}

// Vicfred
// https://codeforces.com/contest/1519/problem/A
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;

while(t--) {
    int r, b, d;
    readf("%s %s %s\n", &r, &b, &d);
    if(r > b)
        swap(r,b);
    if(b <= r*(d + 1))
        "YES".writeln;
    else
        "NO".writeln;
}
}


import std.stdio;
import std.algorithm;
int main()
{
	int t=0;
	readf(" %d", &t);
	for (int i=0; i<t; i++)
	{
		int a=0;
		int b=0;
		int c=0;
		int d=0;
		int e=0;
		readf(" %d", &a);
		readf(" %d", &b);
		readf(" %d", &c);
		readf(" %d", &d);
		readf(" %d", &e);
		int r=a/2;
		int sum=0;
		if (d==e)
		{
			sum=sum+min(r,b+c)*d;
		}
		else
		{
			if (d>e)
			{
				sum=sum+min(r, b)*d+min(r-min(r,b),c)*e;
			}
			else
			{
				sum=sum+min(r, c)*e+min(r-min(r,c),b)*d;
			}
		}
		writeln(sum);
	}
	return 0;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (i; 0..t)
	{
		auto bpf = RDA;
		auto b   = bpf[0];
		auto hc  = RDA;
		long cnt1, cnt2;
		if (hc[0] > hc[1])
		{
			cnt1 = bpf[1];
			cnt2 = bpf[2];
		}
		else
		{
			cnt1 = bpf[2];
			cnt2 = bpf[1];
		}
		auto c1 = min(cnt1, b/2);
		b      -= c1 * 2;
		ans[i] += c1 * max(hc[0], hc[1]);
		auto c2 = min(cnt2, b/2);
		ans[i] += c2 * min(hc[0], hc[1]);
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush();
	debug readln();
}


import std.stdio, std.string;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        readln;
        ulong cnt = readln.chomp.count('0');
        if (cnt == 1)
            writeln("BOB");
        else if (cnt % 2)
            writeln("ALICE");
        else
            writeln("BOB");
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}

		if (cnt % 2)
			ans[ti] = cnt == 1 ? -1 : 1;
		else
			ans[ti] = -1;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;

void main() {
    foreach(t; 0 .. to!int(readln.chomp)) {
        int n = to!int(readln.chomp);
        string s = readln.chomp;
        bool pal = true;
        int open = 0;
        foreach(i; 0 .. s.length/2) {
            if(s[i] == s[$-(1+i)]) {
                if(s[i] == '0') open += 2;
            } else {
                open++;
                pal = false;
            }
        }
        if(pal) {
            if(n == 1) {
                writeln("BOB");
            } else if(n%2) {
                if(s[$/2] == '0' && open) writeln("ALICE");
                else writeln("BOB");
            } else {
                writeln("BOB");
            }

        } else {
        }
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}

		if (cnt % 2)
			ans[ti] = cnt <= 3 ? -1 : 1;
		else
			ans[ti] = -1;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}

		if (cnt % 2)
			ans[ti] = ((cnt/2) % 2) ? 1 : -1;
		else
			ans[ti] = -1;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}

		if (cnt % 2)
			ans[ti] = ((cnt/2) % 2) ? 1 : -1;
		else
			ans[ti] = ((cnt/2) % 2) ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}
		if (cnt == 0) continue;

		if (cnt % 2)
			ans[ti] = (cnt/2) % 2 ? 1 : -1;
		else
			ans[ti] = cnt % 4 ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}
		if (cnt == 0) continue;

		if (n % 2 && s[n/2] == '0')
		{
			if (cnt % 2 == 0)
				ans[ti] = 0;
			else
				ans[ti] = (cnt/2) % 2 ? 1 : -1;
		}
		else
			ans[ti] = cnt % 4 ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD;
		auto s = RD!string;

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}
		if (cnt == 0) continue;
		ans[ti] = cnt % 4 ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD;
		auto s = RD!string;

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}
		ans[ti] = cnt % 4 ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;

void main() {
    foreach(t; 0 .. to!int(readln.chomp)) {
        int n = to!int(readln.chomp);
        string s = readln.chomp;
        bool pal = true;
        int open = 0;
        foreach(i; 0 .. s.length/2) {
            if(s[i] == s[$-(1+i)]) {
                if(s[i] == '0') open += 2;
            } else {
                open++;
                pal = false;
            }
        }
        if(pal) {
            if(n == 1) {
                writeln("BOB");
            } else if(n%2) {
                if(s[$/2] == '0') writeln("ALICE");
                else writeln("BOB");
            } else {
                writeln("BOB");
            }

        } else {
        }
    }
}

import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;

void main() {
    foreach(t; 0 .. to!int(readln.chomp)) {
        int n = to!int(readln.chomp);
        string s = readln.chomp;
        bool pal = true;
        int open = 0;
        foreach(i; 0 .. s.length/2) {
            if(s[i] == s[$-(1+i)]) {
                if(s[i] == '0') open += 2;
            } else {
                open++;
                pal = false;
            }
        }
        if(pal) {
            if(n == 1) {
                writeln("BOB");
            } else if(n%2) {
                if(s[$/2+1] == '0') writeln("ALICE");
                else writeln("BOB");
            } else {
                writeln("BOB");
            }

        } else {
        }
    }
}

import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;

void main() {
    foreach(t; 0 .. to!int(readln.chomp)) {
        int n = to!int(readln.chomp);
        string s = readln.chomp;
        bool pal = true;
        int open = 0;
        foreach(i; 0 .. s.length/2) {
            if(s[i] == s[$-(1+i)]) {
                if(s[i] == '0') open += 2;
            } else {
                open++;
                pal = false;
            }
        }
        if(pal) {
            if(n == 1) {
                writeln("BOB");
            } else if(n%2) {
                writeln("ALICE");
            } else {
                writeln("BOB");
            }

        } else {
        }
    }
}


import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

//	Input
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }
auto pair(S, T)(inout(S) x,       T  y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int root(int[] uf, int u) {
	return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool conn(int[] uf, int u, int v) {
	u = uf.root(u);
	v = uf.root(v);
	if (u == v) return false;
	if (uf[u] > uf[v]) swap(u, v);
	uf[u] += uf[v];
	uf[v] = u;
	return true;
}

Pair!(int, int[]) scc(int[][] g0, int[][] g1) {
	int n = g0.length;
	int compN;
	int[] compIds = new int[n];
	void dfs(int[][] g, int u, int a, int b, ref int[] st) {
		if (compIds[u] == a) {
			compIds[u] = b;
			foreach (v; g[u]) dfs(g, v, a, b, st);
			st ~= u;
		}
	}
	int[] stack, dump;
	foreach (u; 0 .. n) {
		dfs(g0, u, 0, -1, stack);
	}
	for (; !stack.empty; ) {
		int u = stack[$ - 1];
		if (compIds[u] == -1) {
			dfs(g1, u, -1, compN, dump);
			++compN;
		}
		stack.popBack;
	}
	return pair(compN, compIds);
}

int N, M;
int[] A, B;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		M = readInt;
		A = new int[M];
		B = new int[M];
		foreach (i; 0 .. M) {
			A[i] = readInt - 1;
			B[i] = readInt - 1;
		}

		int[] uf = new int[N];
		fill(uf, -1);
		foreach (i; 0 .. M) {
			uf.conn(A[i], B[i]);
		}
		int[][] uComps = new int[][N];
		foreach (u; 0 .. N) {
			uComps[uf.root(u)] ~= u;
		}

		int[][] g0 = new int[][N];
		int[][] g1 = new int[][N];
		foreach (i; 0 .. M) {
			g0[A[i]] ~= B[i];
			g1[B[i]] ~= A[i];
		}
		int[] compIds = scc(g0, g1).y;

		int ans;
		foreach (uComp; uComps) if (!uComp.empty) {
			const int sz = uComp.length;
			int[] ids = new int[sz];
			foreach (j; 0 .. sz) {
				ids[j] = compIds[uComp[j]];
			}
			ids.sort();
			bool ok = true;
			foreach (j; 1 .. sz) {
				ok = ok && (ids[j - 1] != ids[j]);
			}
			ans += ok ? (sz - 1) : sz;
		}
		writeln(ans);
	}
	} catch (EOFException) {}
}

import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) readf(" %s", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }
int ilen(T)(const ref T a) { return cast(int)(a.length); }

enum int N = 10 ^^ 5 + 8;
int n, m;
Array!int[N] graph;
Array!int[N] antigraph;
int[N] outdeg;
bool[N] vis;
Array!int curv;
int cost = 0;

void dfs(int v) {
	if (vis[v]) return;
	curv ~= v;
	vis[v] = true;
	foreach (w; graph[v]) { dfs(w); }
	foreach (w; antigraph[v]) { dfs(w); }
}

SList!int out0;
void solveFrom(int v0) {
	if (!vis[v0]) {
		curv.length = 0;
		dfs(v0);
		out0.clear();
		debug {
			ewriteln("solving from: ", v0);
			ewriteln("  curv cap ", curv.capacity);
			ewriteln("  out0 cap ", out0.capacity);
		}
		int ovs = 0;
		foreach (v; curv) {
			outdeg[v] = graph[v].ilen;
			if (outdeg[v] == 0) {
				out0.insertFront(v);
				ovs++;
			}
		}
		while (!out0.empty) {
			int v = out0.front; out0.removeFront();
			foreach (w; antigraph[v]) {
				assert(outdeg[w] >= 1);
				outdeg[w]--;
				if (outdeg[w] == 0) {
					out0.insertFront(w);
					ovs++;
				}
			}
		}
		cost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;
	}
}

int solve() {
	foreach (i; 1..n+1) { solveFrom(i); }
	return cost;
}

void main() {
	scan(n, m);
	foreach(_; 0..m) {
		int a, b;
		scan(a, b);
		graph[a] ~= b;
		antigraph[b] ~= a;
	}
	writeln(solve());
}

import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) readf(" %s", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }
int ilen(T)(const ref T a) { return cast(int)(a.length); }
void push(T)(ref Array!T a, in T b) {
	if (a.length == a.capacity) a.reserve(2*a.capacity + 1);
	a ~= b;
}

enum int N = 10 ^^ 5 + 8;
int n, m;
Array!int[N] graph;
Array!int[N] antigraph;
int[N] outdeg;
bool[N] vis;
Array!int curv;
int cost = 0;

void dfs(int v) {
	if (vis[v]) return;
	curv.push(v);
	vis[v] = true;
	foreach (w; graph[v]) { dfs(w); }
	foreach (w; antigraph[v]) { dfs(w); }
}

Array!int out0;
void solveFrom(int v0) {
	if (!vis[v0]) {
		curv.length = 0;
		dfs(v0);
		out0.length = 0;
		debug {
			ewriteln("solving from: ", v0);
			ewriteln("  curv cap ", curv.capacity);
			ewriteln("  out0 cap ", out0.capacity);
		}
		int ovs = 0;
		foreach (v; curv) {
			outdeg[v] = graph[v].ilen;
			if (outdeg[v] == 0) {
				out0.push(v);
				ovs++;
			}
		}
		while (!out0.empty) {
			int v = out0.back; out0.removeBack();
			foreach (w; antigraph[v]) {
				assert(outdeg[w] >= 1);
				outdeg[w]--;
				if (outdeg[w] == 0) {
					out0.push(w);
					ovs++;
				}
			}
		}
		cost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;
	}
}

int solve() {
	foreach (i; 1..n+1) { solveFrom(i); }
	return cost;
}

void main() {
	scan(n, m);
	foreach(_; 0..m) {
		int a, b;
		scan(a, b);
		graph[a].push(b);
		antigraph[b].push(a);
	}
	writeln(solve());
}

import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) scanf("%d", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }
int ilen(T)(const ref T a) { return cast(int)(a.length); }
void push(T)(ref Array!T a, in T b) {
	// if (a.length == a.capacity) a.reserve(2*a.capacity + 1);
	a ~= b;
}

enum int N = 10 ^^ 5 + 8;
int n, m;
Array!int[N] graph;
Array!int[N] antigraph;
int[N] outdeg;
bool[N] vis;
Array!int curv;
int cost = 0;

void dfs(int v) {
	if (vis[v]) return;
	curv.push(v);
	vis[v] = true;
	foreach (w; graph[v]) { dfs(w); }
	foreach (w; antigraph[v]) { dfs(w); }
}

Array!int out0;
void solveFrom(int v0) {
	if (!vis[v0]) {
		curv.length = 0;
		dfs(v0);
		out0.length = 0;
		debug {
			ewriteln("solving from: ", v0);
			ewriteln("  curv cap ", curv.capacity);
			ewriteln("  out0 cap ", out0.capacity);
		}
		int ovs = 0;
		foreach (v; curv) {
			outdeg[v] = graph[v].ilen;
			if (outdeg[v] == 0) {
				out0.push(v);
				ovs++;
			}
		}
		while (!out0.empty) {
			int v = out0.back; out0.removeBack();
			foreach (w; antigraph[v]) {
				assert(outdeg[w] >= 1);
				outdeg[w]--;
				if (outdeg[w] == 0) {
					out0.push(w);
					ovs++;
				}
			}
		}
		cost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;
	}
}

int solve() {
	foreach (i; 1..n+1) { solveFrom(i); }
	return cost;
}

void main() {
	scan(n, m);
	foreach(_; 0..m) {
		int a, b;
		scan(a, b);
		graph[a].push(b);
		antigraph[b].push(a);
	}
	writeln(solve());
}

import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) readf(" %s", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }
int ilen(T)(const ref T a) { return cast(int)(a.length); }

enum int N = 10 ^^ 5 + 8;
int n, m;
Array!int[N] graph;
Array!int[N] antigraph;
int[N] outdeg;
bool[N] vis;
Array!int curv;
int cost = 0;

void dfs(int v) {
	if (vis[v]) return;
	curv ~= v;
	vis[v] = true;
	foreach (w; graph[v]) { dfs(w); }
	foreach (w; antigraph[v]) { dfs(w); }
}

Array!int out0;
void solveFrom(int v0) {
	if (!vis[v0]) {
		curv.length = 0;
		dfs(v0);
		out0.length = 0;
		debug {
			ewriteln("solving from: ", v0);
			ewriteln("  curv cap ", curv.capacity);
			ewriteln("  out0 cap ", out0.capacity);
		}
		int ovs = 0;
		foreach (v; curv) {
			outdeg[v] = graph[v].ilen;
			if (outdeg[v] == 0) {
				out0 ~= v;
				ovs++;
			}
		}
		while (!out0.empty) {
			int v = out0.back; out0.removeBack();
			foreach (w; antigraph[v]) {
				assert(outdeg[w] >= 1);
				outdeg[w]--;
				if (outdeg[w] == 0) {
					out0 ~= w;
					ovs++;
				}
			}
		}
		cost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;
	}
}

int solve() {
	foreach (i; 1..n+1) { solveFrom(i); }
	return cost;
}

void main() {
	scan(n, m);
	foreach(_; 0..m) {
		int a, b;
		scan(a, b);
		graph[a] ~= b;
		antigraph[b] ~= a;
	}
	writeln(solve());
}


void main(){
  import std.stdio, std.algorithm, std.string, std.conv;

  struct P{
    int idx1, idx2;
  }
  int K; rd(K);
  P[int] set;
  for(int k=1; k<=K; k++){
    int n; rd(n);
    auto as=readln.split.to!(int[]);
    int s=reduce!"a+b"(as);
    P[] cand;
    foreach(int i, a; as){
      int t=s-a;
      if(t in set){
        if(set[t].idx1<k){
          writeln("YES");
          writeln(set[t].idx1, " ", set[t].idx2);
          writeln(k, " ", i+1);
          return;
        }
      }else{
        set[t]=P(k, i+1);
      }
    }
  }

  writeln("NO");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    Tuple!(int, int)[long] D;

    foreach (i; 0..N) {
        auto M = readln.chomp.to!int;
        auto A = readln.split.map!(to!long).array;
        auto S = A.sum;
        foreach (j; 0..M) {
            auto T = S - A[j];
            if (T in D) {
                if (D[T][0] != i + 1) {
                    writeln("YES");
                    writeln(D[T][0], " ", D[T][1]);
                    writeln(i+1, " ", j+1);
                    return;
                }
            } else {
                D[T] = tuple(i+1, j+1);
            }
        }
    }

    writeln("NO");
}

import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    int[][] a;
    foreach (_; 0..n) {
        readln;
        a ~= readln.chomp.split.map!(to!int).array;
    }

    debug { a.writeln; }

    Tuple!(int, int) [int] v;

    foreach (i, s; a.enumerate(1)) {
        int sm = s.sum;
        foreach (j, e; s.enumerate(1)) {
            int cur = sm - e;
            if (cur in v) {
                writeln("YES");
                writeln(v[cur][0], ' ', v[cur][1]);
                writeln(i, ' ', j);
                return;
            }
        }

        foreach (j, e; s.enumerate(1)) {
            int cur = sm - e;
            v[cur] = tuple(i, j);
        }
    }

    writeln("NO");
}


import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable int mod = 10 ^^ 9 + 7;
immutable int limit = 1003;

void add (ref int a, int b)
{
	a = (a + b) % mod;
}

void main ()
{
	auto h = new int [limit];
	h[1] = 0;
	foreach (i; 2..limit)
	{
		h[i] = h[popcnt (i)] + 1;
	}

	string s;
	while ((s = readln.strip) != "")
	{
		auto k = readln.strip.to !(int);
		if (k == 0)
		{
			writeln (1);
			continue;
		}

		auto n = s.length.to !(int);
		auto f = new int [2] [] [] (n + 1, n + 1);
		f[0][0][0] = 1;
		foreach (i; 0..n)
		{
			int lim = (s[i] == '1');
			foreach (j; 0..i + 1)
			{
				foreach (prevLess; 0..2)
				{
					foreach (cur; 0..2)
					{
						if ((cur > lim) && !prevLess)
						{
							continue;
						}
						int nextLess = prevLess ||
						    (cur < lim);
						add (f[i + 1][j + cur]
						    [nextLess], f[i][j]
						    [prevLess]);
					}
				}
			}
		}
		add (f[n][1][1], mod - 1);

		int res = 0;
		foreach (j; 1..n + 1)
		{
			if (h[j] == k - 1)
			{
				add (res, f[n][j][0]);
				add (res, f[n][j][1]);
			}
		}
		writeln (res);
	}
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp;
    auto K = readln.chomp.to!int;
    auto dp = new int[](1001);
    dp[1] = 1;

    for (int i = 2; i <= 1000; ++i) {
        dp[i] = dp[i.popcnt] + 1;
    }

    auto dp2 = new long[][][](N.length+1, N.length+1, 2);
    dp2[0][0][0] = 1;

    foreach (i; 0..N.length) {
        foreach (j; 0..N.length+1) {
            foreach (k; 0..2) {
                int digit = (k || N[i] == '1') ? 2 : 1;
                foreach (d; 0..digit) {
                    if (j+d <= N.length)
                        (dp2[i+1][j+d][k||(d < N[i]-'0')] += dp2[i][j][k]) %= MOD;
                }
            }
        }
    }

    long ans = 0;
    foreach (i; 1..N.length+1) {
        if (dp[i] == K) {
            (ans += dp2[N.length][i][0]) %= MOD;
            (ans += dp2[N.length][i][1]) %= MOD;
        }
    }

    if (K == 1) {
        ans -= 1;
        ans %= MOD;
    } else if (K == 0) {
        ans = 1;
    }

    ans.writeln;
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct ModInt(int M_) {
  import std.conv : to;
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      if (a < 0) return (this = inv()^^(-a));
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e > 0; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op: "-")() const { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const {
    return mixin("ModInt(this) " ~ op ~ "= a");
  }
  ModInt opBinaryRight(string op)(long a) const {
    return mixin("ModInt(a) " ~ op ~ "= this");
  }
  bool opCast(T: bool)() const { return (x != 0); }
  string toString() const { return x.to!string; }
}

enum MO = 10^^9 + 7;
alias Mint = ModInt!MO;

void main() {
  try {
    for (; ; ) {
      const N = readToken();
      const K = readInt();
      const L = cast(int)(N.length);

      auto numSteps = new int[L + 1];
      foreach (i; 2 .. L + 1) {
        numSteps[i] = 1 + numSteps[popcnt(i)];
      }
      debug {
        writeln("numSteps = ", numSteps);
      }

      auto dp = new Mint[][][](L + 1, 2, L + 1);
      dp[0][0][0] = 1;
      foreach (i; 0 .. L) {
        foreach (s; 0 .. 2) foreach (j; 0 .. i + 1) {
          foreach (x; 0 .. 2) {
            if (s || x <= N[i] - '0') {
              dp[i + 1][(s || x < N[i] - '0') ? 1 : 0][j + x] += dp[i][s][j];
            }
          }
        }
      }
      Mint ans;
      if (K == 0) {
        // 1 <= N
        ans += 1;
      } else {
        foreach (s; 0 .. 2) foreach (j; 1 .. L + 1) {
          if (K == 1 + numSteps[j]) {
            ans += dp[L][s][j];
          }
        }
        if (K == 1) {
          // 1 <= N
          ans -= 1;
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable int mod = 10 ^^ 9 + 7;
immutable int limit = 1003;

void add (ref int a, int b)
{
	a = (a + b) % mod;
}

void main ()
{
	auto h = new int [limit];
	h[1] = 0;
	foreach (i; 2..limit)
	{
		h[i] = h[popcnt (i)] + 1;
	}

	string s;
	while ((s = readln.strip) != "")
	{
		auto k = readln.strip.to !(int);
		if ((k == 0) || (s == "1"))
		{
			int res = (k == 0) && (s == "1");
			writeln (res);
			continue;
		}

		auto n = s.length.to !(int);
		auto f = new int [2] [] [] (n + 1, n + 1);
		f[0][0][0] = 1;
		foreach (i; 0..n)
		{
			int lim = (s[i] == '1');
			foreach (j; 0..i + 1)
			{
				foreach (prevLess; 0..2)
				{
					foreach (cur; 0..2)
					{
						if ((cur > lim) && !prevLess)
						{
							continue;
						}
						int nextLess = prevLess ||
						    (cur < lim);
						add (f[i + 1][j + cur]
						    [nextLess], f[i][j]
						    [prevLess]);
					}
				}
			}
		}
		add (f[n][1][0], mod - 1);

		int res = 0;
		foreach (j; 1..n + 1)
		{
			if (h[j] == k - 1)
			{
				add (res, f[n][j][0]);
				add (res, f[n][j][1]);
			}
		}
		writeln (res);
	}
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct ModInt(int M_) {
  import std.conv : to;
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      if (a < 0) return (this = inv()^^(-a));
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e > 0; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op: "-")() const { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const {
    return mixin("ModInt(this) " ~ op ~ "= a");
  }
  ModInt opBinaryRight(string op)(long a) const {
    return mixin("ModInt(a) " ~ op ~ "= this");
  }
  bool opCast(T: bool)() const { return (x != 0); }
  string toString() const { return x.to!string; }
}

enum MO = 10^^9 + 7;
alias Mint = ModInt!MO;

void main() {
  try {
    for (; ; ) {
      const N = readToken();
      const K = readInt();
      const L = cast(int)(N.length);

      auto numSteps = new int[L + 1];
      foreach (i; 2 .. L + 1) {
        numSteps[i] = 1 + numSteps[popcnt(i)];
      }
      debug {
        writeln("numSteps = ", numSteps);
      }

      auto dp = new Mint[][][](L + 1, 2, L + 1);
      dp[0][0][0] = 1;
      foreach (i; 0 .. L) {
        foreach (s; 0 .. 2) foreach (j; 0 .. i + 1) {
          foreach (x; 0 .. 2) {
            if (s || x <= N[i] - '0') {
              dp[i + 1][(s || x < N[i] - '0') ? 1 : 0][j + x] += dp[i][s][j];
            }
          }
        }
      }
      Mint ans;
      if (K == 0) {
        // 1 <= N
        ans = 1;
      } else {
        foreach (s; 0 .. 2) foreach (j; 1 .. L + 1) {
          if (K == 1 + numSteps[j]) {
            ans += dp[L][s][j];
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import core.bitop;

real vp (real x0, real y0, real x1, real y1, real x2, real y2)
{
	return (x2 - x0) * (y1 - y0) - (x1 - x0) * (y2 - y0);
}

void main ()
{
	int n;
	real p, q;
	while (readf (" %s %s %s", &n, &p, &q) > 0)
	{
		alias Point = Tuple !(real, q{x}, real, q{y});
		auto a = new Point [n];
		foreach (ref z; a)
		{
			readf (" %s %s", &z.x, &z.y);
		}
		sort !((a, b) => (vp (0, 0, a.x, a.y, b.x, b.y) < 0) ||
		    (vp (0, 0, a.x, a.y, b.x, b.y) == 0 &&
		    hypot (a.y, a.x) < hypot (b.y, b.x))) (a);
		a = a.uniq.array;
/*
		Point [] c;
		foreach (ref z; a)
		{
			if (!c.empty &&
			    (vp (0, 0, z.x, z.y, c[0].x, c[0].y) == 0 &&
			    hypot (z.y, z.x) >= hypot (c[0].y, c[0].x)))
			{
				c.popBack ();
				c.assumeSafeAppend ();
			}
			c ~= z;
		}
		debug {writeln (c);}
		a = c;
*/
                n = a.length;
		Point [] b;
		foreach (i; 0..n)
		{
			while (b.length >= 2 &&
			    vp (b[$ - 2].x, b[$ - 2].y,
			    b[$ - 1].x, b[$ - 1].y, a[i].x, a[i].y) > 0)
			{
				b.popBack ();
				b.assumeSafeAppend ();
			}
			b ~= a[i];
		}
		debug {writeln (b);}

		real res = 1E100;
		foreach (i; 0..b.length)
		{
			res = min (res, max (p / b[i].x, q / b[i].y));
			if (i > 0 && vp (0, 0, b[i - 1].x, b[i - 1].y, p, q) *
			    vp (0, 0, b[i].x, b[i].y, p, q) < 0)
			{
				real lo = 0;
				real hi = 1;
				foreach (j; 0..100)
				{
					real me = (lo + hi) * 0.5;
					real ppart1 = me * p;
					real ppart2 = p - ppart1;
					real t1 = ppart1 / b[i - 1].x;
					real t2 = ppart2 / b[i].x;
					real qpart1 = t1 * b[i - 1].y;
					real qpart2 = t2 * b[i].y;
					if (q < qpart1 + qpart2)
					{
						lo = me;
					}
					else
					{
						hi = me;
					}
				}
				debug {writeln (lo);}
				real ppart1 = lo * p;
				real ppart2 = p - ppart1;
				real t1 = ppart1 / b[i - 1].x;
				real t2 = ppart2 / b[i].x;
				res = min (res, t1 + t2);
			}
		}

		writefln ("%.10f", res);
	}
}