let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(j = 1; j<= n; j++){
        var r = false
        var g = false
        var b = false
        var s = false

        var a = lines[j].split('')
        for(k = 0; k < a.length; k++){
            if(a[k] == 'R' && r === false){
            break;
        }else if(a[k] == 'G'&& g === false){
            break;
        }else if(a[k] == 'B' && b === false){
            break;
        }else if(a[k] == 'r'){
            r = true
        }else if(a[k] == 'g'){
            g = true
        }else if(a[k] == 'b'){
            b = true
        }

        }
        if(r === true && g === true & b === true){
            console.log('YES')
        }else{
            console.log('NO')
        }
    }
});

"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let inputData = [];
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString = String(inputStdin);
});
process.stdin.on('end', () => {
    inputData = inputString.trim().split('\n').map(string => string.trim());
    main();
});
const readline = () => inputData[currentLine++];
const solve = (s) => {
    if (s.indexOf('r') > s.indexOf('R'))
        return "NO";
    if (s.indexOf('g') > s.indexOf('G'))
        return "NO";
    if (s.indexOf('b') > s.indexOf('B'))
        return "NO";
    return "YES";
};
const main = () => {
    let tc = parseInt(readline());
    while (tc--) {
        let s = readline();
        console.log(solve(s));
    }
};

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    const x = readline();

    for(let i = 0; i < x; i++){
        debugger;
        let line2 = readline();
        doorKeys(line2);
    }
}

 function doorKeys(word) {
    let len = word.length;
    let kyes = [];

    for(let j = 0; j < len; j++) {
        let asciValue = word[j].charCodeAt(0);

        if(asciValue >= 97 && asciValue <= 122 ) {
            kyes.push(word[j]);
        } else {
           if(!kyes.includes(word[j].toLowerCase())) {
               console.log("NO");
               return;
           }
        }
    }
    console.log('YES');
 }

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', stdin => inputString += stdin);

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(s => s.trim());
    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    let no = false;
    for (let test = 0; test < N; test++) {
        let str = readline();

        let I = {};
        for (let i = 0; i < str.length; i++) I[str[i]] = i;

        let red = I.r < I.R;
        let blue = I.b < I.B;
        let green = I.g < I.G;

        output((red && blue && green) ? 'YES' : 'NO');
    }
}

'use strict';

function solve(s) {
  let set = new Set();
  for (let ch of s) {
    const num = ch.charCodeAt(0);
    if (num > 97) {
      set.add(num - 32);
    } else {
      if (!set.has(num)) return 'NO';
    }
  }
  return 'YES';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const s = await read();
      res[i] = solve(s);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const str = lines[l++]
        output[i] = solve(str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(str) {
    const map = {}
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (/[RGB]/.test(x)) {
            if (!map[x.toLowerCase()]) return 'NO'
        } else {
            map[x] = 1
        }
    }
    return 'YES'
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var S = next();
		var Key = "rgb";
		var Door = "RGB";
		var set = new Set();
		var ok = true;
		for(var i = 0; i < S.length; i++){
			if(Key.indexOf(S[i]) != -1){
				set.add(S[i].toUpperCase());
			}else{
				if(!set.has(S[i])){
					ok = false;
				}
			}
		}
		if(ok){
			myout("YES");
		}else{
			myout("NO");
		}
	}
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine(){
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function processString(st=""){
    let r=false,g=false,b=false;
    const values = {
        r : false,
        g :false,
        b : false
    };
    for(let i=0;i<st.length;i++){
        if(st[i] == "R" || st[i]=="G" || st[i]=="B"){
            let small = st[i].toLowerCase();
            if(values[small]){
                continue;
            }else{
                return false;
            }
        }
        else{
            values[st[i]] = true;
        }
    }

    return true;
}
function solve() {

    const n = readSingleInt();
    let string;
    for(let i =0;i<n;i++){
        string=readLine();
        console.log(processString(string) ? "YES" : "NO");
    }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0].split(' ');
    var answer = 0;
    for(var l = 1; l <= n; l++){
        var k = lines[l].split('');
        var rkey = false;
        var gkey = false;
        var bkey = false;
        var no = false;
        for(var j = 0; j < k.length; j++){
            if(k[j] == 'r'){
                rkey = true;
            }else if(k[j] == 'g'){
                gkey = true;
            }else if(k[j] == 'b'){
                bkey = true;
            }else if(k[j] == 'R' && rkey === false || k[j] == 'G' && gkey === false || k[j] == 'B' && bkey === false){
                no = true;
            }
        }
        if(!no){
            console.log('YES');
        }else{
            console.log('NO');
        }
    }
});

'use strict';
/* ================== */
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

const readline = () => inputString[currentLine++];
const readline_arr = () => readline().split(' ').map((n) => parseInt(n, 10));
const print = (...txt) => process.stdout.write(`${txt}\n`)
/* ================== */

function main() {
  let t = parseInt(readline(), 10);
  while (t--) {
    solve();
  }
}

function solve() {
  const str = readline().split('');

  const keys = [];
  for (let i = 0; i < str.length; i++) {
    const p = str[i];
    if (p === p.toLowerCase()) {
      keys.push(p);
    } else {
      if (keys.some(k => k === p.toLowerCase())) {
        continue;
      } else {
        print('NO');
        return;
      }
    }
  };

  print('YES');
}

function solve(input) {
  let result = 'YES'
    // console.log('input: ', input)
  // for (let char of input) {
  //   console.log(char)
  // }
  const listStr = input.split('');
  const checkRr = listStr.filter(data => ['R', 'r'].includes(data))
  const checkGg = listStr.filter(data => ['G', 'g'].includes(data))
  const checkBb = listStr.filter(data => ['B', 'b'].includes(data))
  if (checkRr[0] === 'R' || checkGg[0] === 'G' || checkBb[0] === 'B') {
    result = 'NO'
  }
  console.log(result)
}

// =========== DEFAULT FORMAT ==============
const readline = require('readline').createInterface({ input: process.stdin });

let i = 1;
let t = 0;
readline.on('line', line => {
    if (i == 1) {
        // number of test case
        t = parseInt(line)
        i++;
    } else {
        solve(line)
        if (i <= t) i++
        else readline.close()
    }
});

// =========== DEFAULT FORMAT END ==============

doorsFilter = (arr)=> {
    return (arr.filter((e)=>{
                return e.toLowerCase() != arr[0];
            }));
};
var t = readline();
    for(var i = 0 ; i < t ; i++){
        var a = readline().split('');
        while(a.length >= 0){
            if(a.length === 0){
                print('YES');
                break;
            }
        if(a[0] == a[0].toLowerCase()){
            a = doorsFilter(a);
        }
        else{
            print('NO');
            break;
        }
    }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    lines.pop();
    const inputCount = Number(lines.shift());
    const results = [];

    const checkInput = (input) => {
        const keys = [ 'r', 'g', 'b' ];
        const doors = [ 'R', 'G', 'B' ];
        const data = input.split('');
        return data.every(
            (element, index, array) =>
                doors.includes(element)
                    ? array.slice(0, index).includes(element.toLowerCase())
                    : true
        );
    };

    for (let inputData of lines) {
        results.push(checkInput(inputData));
    }

    for (var result of results) console.log(result ? 'YES' : 'NO');
})

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    console.log(lines);
    const inputCount = Number(lines.shift());
    const results = [];

    const checkInput = (input) => {
        const keys = [ 'r', 'g', 'b' ];
        const doors = [ 'R', 'G', 'B' ];
        const data = input.split('');
        return data.every(
            (element, index, array) =>
                doors.includes(element)
                    ? array.slice(0, index).includes(element.toLowerCase())
                    : true
        );
    };

    for (let inputData of lines) {
        results.push(checkInput(inputData));
    }

    for (var result of results) console.log(result ? 'YES' : 'NO');
})

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

    const inputCount = Number(lines.shift());
    const results = [];

    const checkInput = (input) => {
        const keys = [ 'r', 'g', 'b' ];
        const doors = [ 'R', 'G', 'B' ];
        const data = input.split('');
        return data.every(
            (element, index, array) =>
                doors.includes(element)
                    ? array.slice(0, index).includes(element.toLowerCase())
                    : true
        );
    };

    for (let inputData of lines) {
        results.push(checkInput(inputData));
    }

    for (var result of results) console.log(result ? 'YES' : 'NO');
})

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var r = false
    var g = false
    var b = false
    var s = false
    for(j = 1; j<= n; j++){
        var a = lines[j].split('')
        for(k = 0; k < a.length; k++){
            if(a[k] == 'R' && r === false){
                s = false
            }else if(a[k] == 'G' && g === false){
                s = false
            }else if(a[k] == 'B' && b === false){
                s = false
            }else{
                s = true
            }
        }
        if(s === false){
            console.log('NO')
        }else{
            console.log('YES')
        }
    }
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    const x = readline();

    for(let i = 0; i < x; i++){
        debugger;
        let line2 = readline();
        doorKeys(line2);
    }
}

 function doorKeys(word) {
    let len = word.length;
    let kyes = [];

    for(let j = 0; j < len; j++) {
        let asciValue = word[j].charCodeAt(0);

        if(asciValue >= 97 && asciValue <= 122 ) {
            kyes.push(word[j]);
        } else {
           if(!kyes.includes(word[j].toLowerCase())) {
               console.log(false);
               return;
           }
        }
    }
    console.log(true);
 }


const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        const arr = lines[l++].trim().split(' ')
        output[i] = solve(n, str, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str, arr) {
    const map = arr.reduce((o, x) => {
        o.set(x, 1)
        return o
    }, new Map())
    let last = -1
    let ans = 0
    for (let i = str.length - 1; i >= 0; i--) {
        ans = Math.max(ans, last < 0 ? -Infinity : last - i)
        if (map.get(str[i])) last = i
    }
    return ans
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
//var alpha = []
var num = []
function alph() {
  var g = []
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var g = []
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  for(var x=0;x<f.length;x++) {
    num[f[x]] = x+1;
    alpha[x+1] = f[x];
  }
  //return g;
}
function max(x,y) {
  return x >=y ? x : y;
}
var T = readline();
for(var q=1;q<=T;q++) {
  var n = readline();
  var s = readline();
  var r = readline().split(' ');
  var alpha = alph();
  var spec = []
  var id = 0;
  var move = 0;
  var m = new Map();
  for(var i=0;i<26;i++) {
    m.set(alpha[i], false);
  }
  for(var i=1;i<=r[0];i++) {
    m.set(r[i], true);
  }
  //console.log(m)

  for(var i=1;i<n;i++) {
    if(m.get(s[i]) === true) {
      if(i-id > move) {
        move = max(move, i-id);
        id = i;
      } else {
        id = i;
      }
    }
  }
  console.log(move);
  //fs.appendFileSync('output.txt', move+'\r\n');

  //os.EOL
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

/*---------------------------------------------------*/

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

/*---------------------------------------------------*/

const calc = (n, s, a)=>{
    let res = 0;

    let map = new Set(a);

    let prev = -1;
    for (let i = 0; i < n - 1; i++) {
        if (map.has(s[i + 1])) {
            res = Math.max(res, i - prev);
            prev = i;
        }
    }

    return res;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let s = readline();
        let a = readline().split(' ').slice(1);
        out.push(calc(n, s, a));
        // console.log(`${calc(n, s, k, a)}`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  let RESULT = [];
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      RESULT.push(calc(T));
  } else
   pcalc();
   process.stdout.write(RESULT.join('\n')+'\n')
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n] = ra();
  let s = readline();
  let K = readline().split(' ');
  let k = +K[0];
  K = new Set(K.slice(1));
  LT({n, s, k, K});
  // PROCESSING:
  let lastPos = -1;
  for (let i=n-1; i>=0; i--){
    if (K.has(s[i])){
      lastPos = i;
      break;
    }
  }
  if (lastPos==-1)
    return 0;
  let cnt = 0;
  let max = 0;
  for (let i=lastPos-1; i>=0; i--){
    if (K.has(s[i+1]))
      cnt = 1;
    else
      cnt++;
    max = Math.max(max, cnt)
  }
  return max
};

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, s, k, b) {
  let pre = 0,
      max = 0;
  const set = new Set(b);
  for (let i = 0; i < n; i++) {
    if (set.has(s[i])) {
      max = Math.max(i - pre, max);
      pre = i;
    }
  }
  return max;
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const n = Number(await read());
    const s = await read();
    const s2 = await read();
    const k = Number(s2[0]);
    const b = s2.slice(2).split(' ');
    res.push(solve(n, s, k, b));
  }
  console.log(res.join('\n'));
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        const arr = lines[l++].trim()//.split(' ')
        output[i] = solve(n, str, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str, arr) {
    const map = {}
    for (let i = 0; i < arr.length; i += 2) {
        map[arr[i]] = 1
    }
    // const map = arr.reduce((o, x) => {
    //     o[x] = 1
    //     return o
    // }, {})
    let last = -1
    let ans = 0
    for (let i = str.length - 1; i >= 0; i--) {
        ans = Math.max(ans, last < 0 ? -Infinity : last - i)
        if (map[str[i]]) last = i
        // if (last >= 0 && last <= ans) break
    }
    return ans
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        const arr = lines[l++]//.trim().split(' ')
        output[i] = solve(n, str, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str, arr) {
    const map = {}
    for (let i = 0; i < arr.length; i += 2) {
        map[arr[i]] = 1
    }
    // const map = arr.reduce((o, x) => {
    //     o[x] = 1
    //     return o
    // }, {})
    let last = -1
    let ans = 0
    for (let i = str.length - 1; i >= 0; i--) {
        ans = Math.max(ans, last < 0 ? -Infinity : last - i)
        if (map[str[i]]) last = i
        // if (last >= 0 && last <= ans) break
    }
    return ans
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        const arr = lines[l++].trim()//.split(' ')
        output[i] = solve(n, str, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str, arr) {
    const map = {}
    for (let i = 0; i < arr.length; i += 2) {
        map[arr[i]] = 1
    }
    // console.log(map)
    let last = -Infinity
    let ans = 0
    for (let i = str.length - 1; i >= 0; i--) {
        if (last - i > ans) {
            ans = last - i
        }
        // ans = Math.max(ans, last < 0 ? -Infinity : last - i)
        if (map[str[i]]) last = i
        // if (last >= 0 && last <= ans) break
    }
    return ans
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        const arr = lines[l++]//.trim().split(' ')
        output[i] = solve(n, str, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str, arr) {
    const map = {}
    for (let i = 0; i < arr.length; i += 2) {
        map[arr[i]] = 1
    }
    // console.log(map)
    let last = -Infinity
    let ans = 0
    for (let i = str.length - 1; i >= 0; i--) {
        // if (last - i > ans) {
        //     ans = last - i
        // }
        ans = Math.max(ans, last < 0 ? -Infinity : last - i)
        if (map[str[i]]) last = i
        // if (last >= 0 && last <= ans) break
    }
    return ans
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        const arr = lines[l++]//.trim().split(' ')
        output[i] = solve(n, str, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str, arr) {
    const map = {}
    for (let i = 0; i < arr.length; i += 2) {
        map[arr[i]] = 1
    }
    // console.log(map)
    let last = -Infinity
    let ans = 0
    for (let i = str.length - 1; i >= 0; i--) {
        if (last - i > ans) {
            ans = last - i
        }
        // ans = Math.max(ans, last < 0 ? -Infinity : last - i)
        if (map[str[i]]) last = i
        // if (last >= 0 && last <= ans) break
    }
    return ans
}


function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1])) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let [r, n] = $(2), a = Arr(n, i => ({ t: $(), x: $(), y: $(), m: 0, c: -1e5 }));
  let res = 0, kc;
  a.unshift({ t: 0, x: 1, y: 1, m: 0, c: 0 });
  for (let i = 1; i <= n; i++) {
    a[i].m = max(a[i].x - 1, r - a[i].x) + max(a[i].y - 1, r - a[i].y)
  }
  for (let i = 1; i <= n; i++) {
    for (let j = i - 1; j >= max(0,i-2000); j--) {
      kc = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
      // if (a[j].t + a[i].m < a[i].t) break;
      if (a[i].c <= a[j].c && kc + a[j].t <= a[i].t) a[i].c = a[j].c + 1;
      if (a[i].c > res) res = a[i].c;
    }
  }
  // log(a)
  log(res)
}

'use strict';

var readline = require('readline');

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

function ownKeys(object, enumerableOnly) {
  var keys = Object.keys(object);

  if (Object.getOwnPropertySymbols) {
    var symbols = Object.getOwnPropertySymbols(object);
    if (enumerableOnly) symbols = symbols.filter(function (sym) {
      return Object.getOwnPropertyDescriptor(object, sym).enumerable;
    });
    keys.push.apply(keys, symbols);
  }

  return keys;
}

function _objectSpread2(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = arguments[i] != null ? arguments[i] : {};

    if (i % 2) {
      ownKeys(Object(source), true).forEach(function (key) {
        _defineProperty(target, key, source[key]);
      });
    } else if (Object.getOwnPropertyDescriptors) {
      Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
      ownKeys(Object(source)).forEach(function (key) {
        Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
      });
    }
  }

  return target;
}

function nInFirstLineArrayStdin(nIndex) {
  return new Promise(resolve => {
    const stdin = readline.createInterface(process.stdin);
    let n;
    let firstLine;
    let output = [];
    stdin.on('line', line => {
      if (typeof n !== 'number') {
        firstLine = line.split(' ').map(Number);
        n = firstLine[nIndex];
      } else {
        output.push(line);

        if (--n === 0) {
          resolve([firstLine, output]);
          stdin.close();
        }
      }
    });
  });
}

function solve(celebs) {
  const scored = [];

  for (let x = 0; x < celebs.length; x++) {
    const current = celebs[x];
    let insertIndex = scored.length;
    let groupScore = -1;
    let inserted = false;

    for (let y = scored.length - 1; y >= 0; y--) {
      const previous = scored[y];

      if (groupScore !== previous.score) {
        insertIndex = y + 1;
        groupScore = previous.score;
      }

      if (Math.abs(current.x - previous.x) + Math.abs(current.y - previous.y) + previous.t <= current.t) {
        scored.splice(insertIndex, 0, _objectSpread2(_objectSpread2({}, current), {}, {
          score: previous.score + 1
        }));
        inserted = true;
        break;
      }
    }

    if (!inserted && current.t >= current.x - 1 + current.y - 1) {
      scored.splice(0, 0, _objectSpread2(_objectSpread2({}, current), {}, {
        score: 1
      }));
    }
  }

  console.log(scored.length ? scored[scored.length - 1].score : 0);
}

async function main() {
  const input = await nInFirstLineArrayStdin(1);
  solve(input[1].map(line => {
    const [t, x, y] = line.split(' ').map(Number);
    return {
      t,
      x,
      y
    };
  }));
}

main().then();

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1])) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let [r, n] = $(2), a = Arr(n, i => ({ t: $(), x: $(), y: $(), m: 0, c: -1e5 }));
  let res = 0, kc;
  a.unshift({ t: 0, x: 1, y: 1, m: 0, c: 0 });
  for (let i = 1; i <= n; i++) {
    a[i].m = max(a[i].x - 1, r - a[i].x) + max(a[i].y - 1, r - a[i].y)
  }
  for (let i = 1; i <= n; i++) {
    for (let j = i - 1; j >= 0; j--) {
      kc = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
      if (a[j].t + kc < a[i].t) break;
      if (a[i].c <= a[j].c && kc + a[j].t <= a[i].t) a[i].c = a[j].c + 1;
      if (a[i].c > res) res = a[i].c;
    }
  }
  // log(a)
  log(res)
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1])) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let [r, n] = $(2), a = Arr(n, i => ({ t: $(), x: $(), y: $(), m: 0, c: -1e5 }));
  let res = 0, kc;
  a.unshift({ t: 0, x: 1, y: 1, m: 0, c: 0 });
  for (let i = 1; i <= n; i++) {
    a[i].m = max(a[i].x - 1, r - a[i].x) + max(a[i].y - 1, r - a[i].y)
  }
  for (let i = 1; i <= n; i++) {
    for (let j = i - 1; j >= max(0,i-1000); j--) {
      kc = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
      // if (a[j].t + a[i].m < a[i].t) break;
      if (a[i].c <= a[j].c && kc + a[j].t <= a[i].t) a[i].c = a[j].c + 1;
      if (a[i].c > res) res = a[i].c;
    }
  }
  // log(a)
  log(res)
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1])) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let [r, n] = $(2), a = Arr(n, i => ({ t: $(), x: $(), y: $(), m: 0, c: -1e5 }));
  let res = 0, kc;
  a.unshift({ t: 0, x: 1, y: 1, m: 0, c: 0 });
  for (let i = 1; i <= n; i++) {
    a[i].m = max(a[i].x - 1, r - a[i].x) + max(a[i].y - 1, r - a[i].y)
  }
  for (let i = 1; i <= n; i++) {
    for (let j = i - 1; j >= 0; j--) {
      kc = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
      if (a[j].t + a[i].m < a[i].t) break;
      if (a[i].c <= a[j].c && kc + a[j].t <= a[i].t) a[i].c = a[j].c + 1;
      if (a[i].c > res) res = a[i].c;
    }
  }
  // log(a)
  log(res)
}


var piles_number = readline();
var piles = readline().split(' ');
var expected_worm_numbers = readline();
var expected_worms = readline().split(' ');

var getWormsAfterPile = function(piles_number, piles) {
    var worms_after_piles = [];
    for (i = 0; i < piles_number; i++) {
        var last_worm_after_pile = (i == 0) ? 0 : worms_after_piles[i - 1];
        worms_after_piles[i] = last_worm_after_pile + parseInt(piles[i]);
    }
    return worms_after_piles;
}

var getWormPile = function(worms_after_piles, expected_worm, start) {
    if (worms_after_piles[0] >= expected_worm) {
        return 1;
    }
    for (i = start, worms_after_piles_length = worms_after_piles.length; i < worms_after_piles_length; i++ ) {
        if (worms_after_piles[i] >= expected_worm && worms_after_piles[i-1] < expected_worm) {
            return i+1;
        }
    }
}

var result = [];

var worms_after_piles = getWormsAfterPile(piles_number, piles);
var sorted_expected_worms = expected_worms.concat().sort(function(a, b) {return a - b;});
var last_worm_pile = 1;
for (k = 0; k < expected_worm_numbers; k++) {
    if (result[sorted_expected_worms[k]] != void(0)) {
        continue;
    }
    var worm_pile = getWormPile(worms_after_piles, sorted_expected_worms[k], last_worm_pile - 1);
    last_worm_pile = result[sorted_expected_worms[k]] = worm_pile;
}

for (l = 0; l < expected_worm_numbers; l++) {
    print(result[expected_worms[l]]);
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  let piles = readline();
  let worms = readline().split(' ');
  worms = worms.map(n => parseInt(n));
  let juicy = readline();
  let juicyWormsLabels = readline().split(' ');
  juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));
  getWormPositions(worms, juicyWormsLabels)
}

function getWormPositions(worms, labels) {
  let res = [];
  let total = new Array(worms.length).fill(0);
  total[0] = worms[0];
  for (let i = 1; i < worms.length; i++) {
    total[i] += total[i - 1] + worms[i]
  }
  for (let i = 0; i < labels.length; i++) {
    let cur = labels[i];
    let idx = bs(total, cur);
    res.push(idx + 1);
  }
  res.forEach(n => console.log(n));
  return res;
}

function bs(arr, target) {
  if (!arr.length) return -1;

  let ini = 0;
  let fin = arr.length - 1;

  while(ini < fin){
      let mid = Math.floor((ini + fin) / 2);
      if(arr[mid] < target){
          ini = mid + 1;
      } else {
          fin = mid;
      }

  }
    return fin;

}

readline()
var A=readline().split(' ').map(Number)
readline()
var Q=readline().split(' ').map(Number)

var T=new Array(A.length + 1)
T[0]=0
for (var i=1; i<T.length; ++i)
    T[i]=T[i-1]+A[i-1];

var find = x => {
    var lb=0,ub=T.length-1;
    while (lb+1<ub) {
        var m=(ub+lb)>>1;
        if (x<=T[m])
            ub=m;
        else if (T[m]<x)
            lb=m;
    }
    return lb;
}

print(Q.map(x => find(x) + 1).join('\n'))

var aMap = {}, aCount = 1, result = [];

var n = parseInt(readline()),
	as = readline().split(/\s/).map(function(a, index)	{
		var i = aCount;

		a = parseInt(a);

		for(; i < aCount + a; i++)	aMap[i] = index + 1;

		aCount = i;

		return a;
	}),
	m = parseInt(readline()),
	qs = readline().split(/\s/).map(function(q, index)	{
		var value = aMap[q];

		if(value)	result.push(value);
	});

print(result.join('\n'));

var n = readline();
var a = readline().split(" ");
for (p in a){a[p]= parseInt(a[p]);}
var m = readline();
var q = readline().split(" ");
for (o in q){q[o]= parseInt(q[o]);}
var z = [];
var r = 0;
for (j = 0;j<a.length;j++){
		a[j]= parseInt(a[j]);
		for (w=1;w<=a[j];w++)
		z[r++] = j+1;
		}
for (i in q){
	print(z[q[i]-1]);
		}

var n = parseInt(readline());
var A = readline().split(' ');
var aa = new Array();
aa[0]=0;
// 0 2 9 12 16 25
for(var i=0;i<A.length;i++)
{
    var t = parseInt(A[i]);
	aa[i+1]=aa[i]+t;
}
var m = parseInt(readline());
var B = readline().split(' ');

for(var i=0;i<B.length;i++)
{
    var val = parseInt(B[i]);
	print(getID(val));
}

function getID(val)
{
    if(val<=aa[1])
	{
	    return 1;
	}
    var st = 1;
	var ed = A.length;
	while(ed>st+1)
	{
	    var mid = (st+ed)>>1;
		if(aa[mid]<val)
		{
		    st = mid;
		}
		else
		{
		    ed = mid;
		}
	}
	return ed;
}

function sum(array){
	var result = 0;
	for(var i = 0; i < array.length; i++){
		result += +array[i];
	}
	return result;
}

var n = +readline(), a = readline().split(" ").map(Number), m = +readline(),
q = readline().split(" ").map(Number);
var array = [], all = sum(a), cnt = a[0];

for(var i = 1, j = 1; i <= all; i++){
	if(i <= cnt){
		array[i] = j;
	}
	else{
		cnt += a[j];
		j++;
		array[i] = j;
	}
}

for(i = 0; i < m; i++){
	print(array[q[i]]);
}

var x = parseInt(readline());

var arr= readline().split(' ').map(a => parseInt(a));

for(var i=1; i<arr.length; i++){
  arr[i] += arr[i-1];
}

var input = parseInt(readline());
var find= readline().split(' ').map(a => parseInt(a));

for(var index=0; index<input; index++){
  var left=0, right = x-1, found=0;
  while(left<=right){
    var mid = left+Math.floor((right-left)/2);
    if(find[index] === arr[mid]){
      found=1;
      break;
    }else if(find[index]>arr[mid]){
      left=mid+1;
    }else{
      right=mid-1;
    }
  }
  if(found===1)
    print(mid+1);
  else{
    if(right<0 || find[index]>arr[right])
    print(left+1);
    if(left>x-1 || find[index]<arr[right])
    print(right+1);
  }

}

function Bst(arr, x) {
  var start = 0,
    end = arr.length - 1,
    mid;
  while (start < end) {
    mid = Math.floor((start + end) / 2);
    if (x < arr[mid]) end = mid;
    if (x > arr[mid]) start = mid + 1;
    if (x == arr[mid]) return mid + 1;
  }
  return start + 1;
}
/************************************** */

var n = parseInt(readline());
var prev = 0;
var a = readline()
  .split(" ")
  .map((val) => {
    var x = parseInt(val);
    x += prev;
    prev = x;
    return x;
  });
var m = parseInt(readline());
var q = readline()
  .split(" ")
  .map((val) => parseInt(val));

for (var i = 0; i < m; i++) {
  print(Bst(a, q[i]));
}

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var out ='';

var arrQnew = [];

for (var i = 0; i < m; i++) {
    arrQnew[i] = [];
    arrQnew[i][0] = arrQ[i];
    arrQnew[i][1] = i;
}

arrQnew.sort(function(a,b){return a[0]-b[0];});

var sum = arrA[0];
var jsum = 0;
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQnew[i][0]) {
            arrOut[arrQnew[i][1]] = j + 1;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[i] + '\n';
};

print(out);

(function () {
    var heapsCount = parseInt(readline()),
        heaps = readline().split(" "),
        wormsCount = parseInt(readline()),
        worms = readline().split(" "),
        arrayHeaps = [],
        i = 1,
        wholeWorms = [],
        wholeWormsCount, j;

    arrayHeaps.push(parseInt(heaps[0]));
    for (; i < heapsCount; i++) {
        arrayHeaps.push(arrayHeaps[i - 1] + parseInt(heaps[i]));
    }
    wholeWormsCount = arrayHeaps[i - 1];
    j = 0;
    for (i = 0; i < wholeWormsCount + 1; i++) {
        wholeWorms.push(j + 1);
        if (i === arrayHeaps[j]) {
            j++;
        }
    }
    for (i = 0; i < wormsCount; i++) {
        print(wholeWorms[parseInt(worms[i])]);
    }
})();

function ProblemSolver() {

    this.solveCase = function() {
        var res , i , j , a , b , c , lo , hi , mi;
        this.cn = 0;
        res = 0;
        for( i = 0 ; i < this.n ; i++ ) {
            a = this.arr[ i ];
            for( j = 0 ; j < a ; j++ ) {
                this.brr[ this.cn++ ] = i + 1;
            }
        }
        for( i = 0 ; i < this.q ; i++ ) {
            a = this.crr[ i ];
            res = this.brr[ a - 1 ] ;
            print( res );
        }
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr[ i ] = irObj.nextInt();
            }
            this.q = irObj.nextInt();
            for( i = 0 ; i < this.q ; i++ ) {
                this.crr[ i ] = irObj.nextInt();
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.brr = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        //this.clearArraysPerCase() ;
    };

    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.crr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.crr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init = function() {
        this.lim1 = 1000010;
        this.lim2 = 110;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.memsetArray1D = function( arrParam , val ) {
        var i;
        if( arrParam == null ) {
            throw new Error( "No array supplied in the parameter!" );
        }
        if( val == null ) {
            throw new Error( "No value for memset has been supplied in the parameter!" );
        }
        arrParam = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            arrParam.push( val );
        }
        return arrParam;
    };

    this.getStringLength = function( stringData ) {
        var len , lengthType;
        len = stringData.length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = stringData.length();
        }
        else {
            len = stringData.length;
        }
        return len;
    };

    this.init();
}

function InputReader() {
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhinoStdin = function() {
        importPackage( java.io );
        importPackage( java.lang );
        var singleLine , reader;
        reader = new BufferedReader( new InputStreamReader( System[ "in" ] ) );
        this.allLines = [];
        while( true ) {
            singleLine = reader.readLine();
            if( singleLine != null ) {
                this.allLines.push( singleLine );
            }
            else {
                break;
            }
        }
    };

    this.readAllLinesFromNodeStdin = function() {
        var fsObj , size , rawData;
        process.stdin.setEncoding( 'ascii' );
        fsObj = require( 'fs' );
        size = fsObj.fstatSync( process.stdin.fd ).size;
        rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];
        this.parseRawData( rawData );
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx , lengthType;
        len = this.allLines[ this.currrentLineNumber ].length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = this.allLines[ this.currrentLineNumber ].length();
        }
        if( flag == 0 ) {
            res = "";
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\t'.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = -1;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\t'.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            if( endIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            else {
                this.currrentCharacterIndex = endIdx;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        if( currentDirectory.charAt( 1 ) != ":" ) {
            //not local machine/windows
            outputFilePath = outputFileName;
        }
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCode = function() {
        var testCases , i , hasMoreTestCases , isLocalMachine , localContext;
        isLocalMachine = false;
        try {
            if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {
                //only on windows
                isLocalMachine = true;
            }
        }
        catch( ex ) {
            isLocalMachine = false;
        }
        if( isLocalMachine == true ) {
            //local machine runs on node and relies on file i/o
            print = console.log;
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
        }
        else {
            //server machine
            try {
                var rlObj = readline;
                //server runs on javasctipt v8 distribution and has readline method on global context
                this.irObj.readAllLines();
            }
            catch( ex ) {
                try {
                    var pObj = process;
                    //server runs on node
                    print = console.log;
                    this.irObj.readAllLinesFromNodeStdin();
                }
                catch( ex ) {
                    try {
                        var ipObj = importPackage;
                        //server runs on rhino
                        this.irObj.readAllLinesFromRhinoStdin();
                    }
                    catch( ex ) {
                        throw new Error( "Unknown javasctipt distribution!" );
                    }
                }
            }
        }
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            //only works for local machine(tested)
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.runCode();
}

new CodeExecutioner();

var n = Number(readline());
var A = readline().split(' ').map(Number)

var m = Number(readline());
var Q = readline().split(' ').map(Number)

for (var i = 1; i < n; i++) {
    A[i] += A[i-1]
}

var lower_bound = function(A, x) {
    var l = 0;
    var r = A.length - 1;

    while (l <= r) {
        var m = Math.floor((l + r) / 2);
        if (A[m] < x) {
            l = m + 1;
        }
        else {
            r = m - 1;
        }
    }
    return l;
}

for (i in Q) {
    print(lower_bound(A, Q[i]) + 1);
}

var x = parseInt(readline());

var arr= readline().split(' ').map(a => parseInt(a));

for(var i=1; i<arr.length; i++){
  arr[i] += arr[i-1];
}

var input = parseInt(readline());
var find= readline().split(' ').map(a => parseInt(a));

for(var index=0; index<input; index++){
  var left=0, right = x-1;
  while(left<=right){
    var mid = Math.floor((left+right)/2);
    if(find[index] === arr[mid]){
      break;
    }else if(find[index]>arr[mid]){
      left=mid+1;
    }else{
      right=mid-1;
    }
  }
  if(left===right)
    print(mid+1);
  if(right<0 || find[index]>arr[right])
    print(left+1);
  if(left>x-1 || find[index]<arr[right])
    print(right+1);
}

var x = parseInt(readline());

var arr= readline().split(' ').map(a => parseInt(a));

for(var i=1; i<arr.length; i++){
  arr[i] += arr[i-1];
}

var input = parseInt(readline());
var find= readline().split(' ').map(a => parseInt(a));

for(var index=0; index<input; index++){
  var left=0, right = x-1;
  while(left<=right){
    var mid = left+Math.floor((right-left)/2);
    if(find[index] === arr[mid]){
      break;
    }else if(find[index]>arr[mid]){
      left=mid+1;
    }else{
      right=mid-1;
    }
  }
  if(left===right)
    print(mid+1);
  if(right<0 || find[index]>arr[right])
    print(left+1);
  if(left>x-1 || find[index]<arr[right])
    print(right+1);
}

function Bst(arr, x) {
  var start = 0,
    end = arr.length - 1,
    mid;
  while (start < end) {
    mid = Math.floor((start + end) / 2);
    if (x < arr[mid]) end = mid;
    if (x > arr[mid]) start = mid + 1;
    if (x == arr[mid]) return mid;
  }
  return start + 1;
}
/************************************** */

var n = parseInt(readline());
var prev = 0;
var a = readline()
  .split(" ")
  .map((val) => {
    var x = parseInt(val);
    x += prev;
    prev = x;
    return x;
  });
var m = parseInt(readline());
var q = readline()
  .split(" ")
  .map((val) => parseInt(val));

for (var i = 0; i < m; i++) {
  print(Bst(a, q[i]));
}

var piles_number = readline();
var piles = readline().split(' ');
var expected_worm_numbers = readline();
var expected_worms = readline().split(' ');

var getWormsAfterPile = function(piles_number, piles) {
    var worms_after_piles = [];
    for (i = 0; i < piles_number; i++) {
        var last_worm_after_pile = (i == 0) ? 0 : worms_after_piles[i - 1];
        worms_after_piles[i] = last_worm_after_pile + parseInt(piles[i]);
    }
    return worms_after_piles;
}

var getWormPile = function(worms_after_piles, expected_worm, start) {
    if (worms_after_piles[0] >= expected_worm) {
        return 1;
    }
    for (i = start, worms_after_piles_length = worms_after_piles.length; i < worms_after_piles_length; i++ ) {
        if (worms_after_piles[i] >= expected_worm && worms_after_piles[i-1] < expected_worm) {
            return i+1;
        }
    }
}

var result = [];

var worms_after_piles = getWormsAfterPile(piles_number, piles);
var sorted_expected_worms = expected_worms.concat().sort(function(a, b) {return a - b;});
var last_worm_pile = 0;
for (k = 0; k < expected_worm_numbers; k++) {
    if (result[sorted_expected_worms[k]] != void(0)) {
        continue;
    }
    var worm_pile = getWormPile(worms_after_piles, sorted_expected_worms[k], last_worm_pile);
    last_worm_pile = result[sorted_expected_worms[k]] = worm_pile;
}

print(expected_worms);
for (l = 0; l < expected_worm_numbers; l++) {
    print(result[expected_worms[l]]);
}

var piles_number = readline();
var piles = readline().split(' ');
var expected_worm_numbers = readline();
var expected_worms = readline().split(' ');

var getWormsAfterPile = function(piles_number, piles) {
    var worms_after_piles = [];
    for (i = 0; i < piles_number; i++) {
        var last_worm_after_pile = (i == 0) ? 0 : worms_after_piles[i - 1];
        worms_after_piles[i] = last_worm_after_pile + parseInt(piles[i]);
    }
    return worms_after_piles;
}

var getWormPile = function(worms_after_piles, expected_worm, start) {
    if (worms_after_piles[0] >= expected_worm) {
        return 1;
    }
    for (i = start, worms_after_piles_length = worms_after_piles.length; i < worms_after_piles_length; i++ ) {
        if (worms_after_piles[i] >= expected_worm && worms_after_piles[i-1] < expected_worm) {
            return i+1;
        }
    }
}

var result = [];

var worms_after_piles = getWormsAfterPile(piles_number, piles);
var sorted_expected_worms = expected_worms.concat().sort(function(a, b) {return a - b;});
var last_worm_pile = 0;
for (k = 0; k < expected_worm_numbers; k++) {
    if (result[sorted_expected_worms[k]] != void(0)) {
        continue;
    }
    var worm_pile = getWormPile(worms_after_piles, sorted_expected_worms[k], last_worm_pile);
    last_worm_pile = result[sorted_expected_worms[k]] = worm_pile;
}

for (l = 0; l < expected_worm_numbers; l++) {
    print(result[expected_worms[l]]);
}

var n = readline();
var a = readline().split(" ");
var m = readline();
var q = readline().split(" ");
var z = [0];
for (j = 0;j<a.length;j++){
		z[j+1] = z[j] + a[j];
		}
for (i in q){
	se:for (j = 1;j<z.length;j++)
		if (q[i]<=z[j]) {
		print(j);
		break se;
		}
}

var n = readline();
var a = readline().split(" ");
for (p in a){a[p]= parseInt(a[p]);}
var m = readline();
var q = readline().split(" ");
for (o in q){q[o]= parseInt(q[o]);}
var se = 0;
var y =0;
for (i = 0;i<a.length;i++){
	y = 0;
	sr: for (j = 0;j<a.length;j++){
		if (q[i]<=(y + a[j])&&q[i]>y) {se = j+1;
		break sr;}
		y = y + a[j];
		}
		print(se);
	}

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            out += (j + 1).toString() + '\n';
            break;
        } else {
            sum += arrA[i+1];
            jsum = j + 1;
        };
    };
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[i] = (j + 1).toString() + '\n';
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[arrQnum[i]] + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

arrA.push(0);

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[arrQnum[arrQ[i]]] = j + 1;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[i] + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[arrQnum[arrQ[i]]] = j;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[i] + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]-1] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[i] = j + '\n';
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[arrQnum[i]] + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var out ='';

var arrQnum = [];

for (var i = 0; i < m; i++) {
    arrQ[i][0] = arrQ[i];
    arrQ[i][1] = i;
}

arrQ.sort(function(a,b){return a[0]-b[0];});

var sum = arrA[0];
var jsum = 0;
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i][0]) {
            arrOut[arrQ[i][1]] = j + 1;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[i] + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]-1] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[i] = j;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += (arrOut[arrQnum[i]] + 1) + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var out ='';

var arrQnum = [];
for (var i = 0; i < m; i++) {
    if (arrQnum[arrQ[i]] == undefined) {
        arrQnum[arrQ[i]] = i;
    } else {
        out = 'duble';
    }
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[arrQnum[arrQ[i]]] = j + 1;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    if (arrOut[i] !== undefined) {
        out += arrOut[i] + '\n';
    };
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[arrQnum[arrQ[i]]] = j + 1;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[i] + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

arrA.push(0);
arrA.push(0);

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[arrQnum[arrQ[i]]] = j + 1;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    if (arrOut[i] !== undefined) {
        out += arrOut[i] + '\n';
    };
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

arrA.push(0);
arrA.push(0);

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[arrQnum[arrQ[i]]] = j + 1;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[i] + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            out += (j + 1).toString() + '\n';
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var arrQnum = [];
for (var i = 0; i < m; i++) {
    arrQnum[arrQ[i]] = i;
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var out ='';
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[i] = (j + 1) + '\n';
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    out += arrOut[arrQnum[i]] + '\n';
};

print(out);

// 474B     Черви

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);
var arrA = readline().split(' ').map(Number);

var m = parseInt(readline());

var arrQ = readline().split(' ').map(Number);

var out ='';

var arrQnum = [];
for (var i = 0; i < m; i++) {
    if (arrQnum[arrQ[i]] == undefined) {
        arrQnum[arrQ[i]] = i;
    } else {
        out += 'duble';
    }
}

arrQ.sort(function(a,b){return a-b;});

var sum = arrA[0];
var jsum = 0;
var arrOut = [];

for (var i = 0; i < m; i++) {
    for (var j = jsum; j < n; j++) {
        if (sum >= arrQ[i]) {
            arrOut[arrQnum[arrQ[i]]] = j + 1;
            break;
        } else {
            sum += arrA[j+1];
            jsum = j + 1;
        };
    };
};

for (var i = 0; i < m; i++) {
    if (arrOut[i] !== undefined) {
        out += arrOut[i] + '\n';
    };
};

print(out);

readline()
var A=readline().split(' ').map(Number)
readline()
var Q=readline().split(' ').map(Number)

var T=new Array(A.length + 1)
T[0]=0
for (var i=1; i<T.length; ++i)
    T[i]=T[i-1]+A[i-1];

var find = x => {
    var lb=0,ub=T.length-1;
    while (1) {
        var m=(ub+lb)>>1;
        if (x<T[m]) {
            ub=m;
        } else if (T[m]<x) {
            lb=m;

        } else return m;
        if (ub===lb+1) return lb;
    }
}

print(Q.map(x => find(x) + 1).join('\n'))

function getWormPositions(worms, labels){
   let total = new Array(worms.length).fill(0);
   total[0] = worms[0];
   for (let i = 1; i < worms.length; i++) {
     total[i] = total[i -1] +  worms[i];
   }

  for (let i = 0; i < labels.length; i++) {
    let cur = labels[i];
    let idx = bs(total, cur);
    console.log(idx + 1)
  }

}

function bs(arr, target){
  if(!arr.length) return -1;

  let mid = Math.floor(arr.length / 2);

  let prev = (mid - 1 ) > -1  ? arr[mid - 1]: -1;

  if(arr[mid] >= target && prev < target){
    return mid;
  } else if(arr[mid] > target){
    return bs(arr.slice(0, mid), target);
  } else if(arr[mid] < target){
    let sub = bs(arr.slice(mid + 1), target);
     return sub >= 0 ? sub + 1 + mid : -1;
  }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  let piles = readline();
  let worms = readline().split(' ');
  worms = worms.map(n => parseInt(n));
  let juicy = readline();
  let juicyWormsLabels = readline().split(' ');
  juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));
  getWormPositions(worms, juicyWormsLabels)
}

function getWormPositions(worms, labels) {
  let res = [];
  let total = new Array(worms.length).fill(0);
  total[0] = worms[0];
  for (let i = 1; i < worms.length; i++) {
    total[i] += total[i - 1] + worms[i]
  }
  for (let i = 0; i < labels.length; i++) {
    let cur = labels[i];
    let idx = bs(total, cur);
    res.push(idx + 1);
  }
  res.forEach(n => console.log(n));
  return res;
}

function bs(arr, target) {
//   console.log(arr, target)
  if (!arr.length) return -1;

  let mid = Math.floor(arr.length / 2);
  let prev = (mid - 1) > -1 ? arr[mid - 1] : - Infinity;

  if (arr[mid] === target) {
    return mid;
  } else if (arr[mid] > target) {
    return bs(arr.slice(0, mid), target);
  } else {
    let sub = bs(arr.slice(mid + 1), target);
    return sub >= 0 ? sub + 1 + mid : -1;
  }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  let piles = readline();
  let worms = readline().split(' ');
  worms = worms.map(n => parseInt(n));
  let juicy = readline();
  let juicyWormsLabels = readline().split(' ');
  juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));
  getWormPositions(worms, juicyWormsLabels)
}

function getWormPositions(worms, labels){
  let res = [];
  let total = new Array(worms.length).fill(0);
  total[0] = worms[0];
  for (let i = 1; i < worms.length; i++) {
    total[i] = total[i -1] +  worms[i];
  }

  for (let i = 0; i < labels.length; i++) {
    let cur = labels[i];
    let idx = bs(total, cur);
    res.push(idx + 1);
  }
  res.forEach(n => console.log(n));
  return res;
}

function bs(arr, target){
  if(!arr) return -1;

  let mid = Math.floor(arr.length / 2);
  let prev = mid - 1 >= 0 ? arr[mid - 1] : - Infinity;
  if(arr[mid] >= target && prev < target){
    return mid;
  } else if(arr[mid] > target){
    return bs(arr.slice(0, mid), target);
  } else if(arr[mid] < target){
    let sub = bs(arr.slice(mid + 1), target);
     return sub > 0 ? sub + 1 + mid : -1;
  }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  let piles = readline();
  let worms = readline().split(' ');
  worms = worms.map(n => parseInt(n));
  let juicy = readline();
  let juicyWormsLabels = readline().split(' ');
  juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));
  getWormPositions(worms, juicyWormsLabels)
}

function getWormPositions(worms, labels) {
  let res = [];
  let total = new Array(worms.length).fill(0);
  total[0] = worms[0];
  for (let i = 1; i < worms.length; i++) {
    total[i] += total[i - 1] + worms[i]
  }
  for (let i = 0; i < labels.length; i++) {
    let cur = labels[i];
    let idx = bs(total, cur);
    res.push(idx + 1);
  }
  res.forEach(n => console.log(n));
  return res;
}

function bs(arr, target) {
//   console.log(arr, target)
  if (!arr.length) return -1;

  let mid = Math.floor(arr.length / 2);
  let prev = (mid - 1) > -1 ? arr[mid - 1] : - Infinity;
  console.log(arr[mid], "current element", prev, "prev", target)

  if (arr[mid] === target) {
    return mid;
  } else if (arr[mid] > target) {
    return bs(arr.slice(0, mid), target);
  } else {
    let sub = bs(arr.slice(mid + 1), target);
    return sub >= 0 ? sub + 1 + mid : -1;
  }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  let piles = readline();
  let worms = readline().split(' ');
  worms = worms.map(n => parseInt(n));
  let juicy = readline();
  let juicyWormsLabels = readline().split(' ');
  juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));
  getWormPositions(worms, juicyWormsLabels)
}
function getWormPositions(worms, labels){
  let res = [];
  let total = new Array(worms.length).fill(0);
  total[0] = worms[0];
  for (let i = 1; i < worms.length; i++) {
    total[i] = total[i -1] +  worms[i];
  }
  console.log(total, "total")

  for (let i = 0; i < labels.length; i++) {
    let cur = labels[i];
    let idx = bs(total, cur);
    res.push(idx + 1);
  }
  res.forEach(n => console.log(n));
  return res;
}

function bs(arr, target){
  if(!arr) return -1;

  let mid = Math.floor(arr.length / 2);
  let prev = mid - 1 >= 0 ? arr[mid - 1] : - Infinity;
  if(arr[mid] >= target && prev < target){
    return mid;
  } else if(arr[mid] > target){
    return bs(arr.slice(0, mid), target);
  } else if(arr[mid] < target){
    let sub = bs(arr.slice(mid + 1), target);
     return sub > 0 ? sub + 1 + mid : -1;
  }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  let piles = readline();
  let worms = readline().split(' ');
  worms = worms.map(n => parseInt(n));
  let juicy = readline();
  let juicyWormsLabels = readline().split(' ');
  juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));
  getWormPositions(worms, juicyWormsLabels)
}

function getWormPositions(worms, labels){
  let res = [];
   let total = new Array(worms.length).fill(0);
   total[0] = worms[0];
   for (let i = 1; i < worms.length; i++) {
     total[i] = total[i -1] +  worms[i];
   }

 labels.sort((a,b) => a - b);

  for (let i = 0; i < labels.length; i++) {
    let cur = labels[i];
    let idx = bs(total, cur);
    res.push(idx + 1);
  }
  res.forEach(n => console.log(n));
  return res;
}

function bs(arr, target){
  if(!arr) return -1;

  let mid = Math.floor(arr.length / 2);

  let prev = (mid - 1 ) > -1  ? arr[mid - 1]: -1;

  if(arr[mid] >= target && prev < target){
    return mid;
  } else if(arr[mid] > target){
    return bs(arr.slice(0, mid), target);
  } else if(arr[mid] < target){
    let sub = bs(arr.slice(mid + 1), target);
     return sub >= 0 ? sub + 1 + mid : -1;
  }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  let piles = readline();
  let worms = readline().split(' ');
  worms = worms.map(n => parseInt(n));
  let juicy = readline();
  let juicyWormsLabels = readline().split(' ');
  juicyWormsLabels = juicyWormsLabels.map(n => parseInt(n));
  getWormPositions(worms, juicyWormsLabels)
}

function getWormPositions(worms, labels){
  let res = [];
   let total = new Array(worms.length).fill(0);
   total[0] = worms[0];
   for (let i = 1; i < worms.length; i++) {
     total[i] = total[i -1] +  worms[i];
   }

  for (let i = 0; i < labels.length; i++) {
    let cur = labels[i];
    let idx = bs(total, cur);
    res.push(idx + 1);
  }
  res.forEach(n => console.log(n));
  return res;
}

function bs(arr, target){
  if(!arr) return -1;

  let mid = Math.floor(arr.length / 2);
  // console.log(mid + 1, arr.length)
  let prev = (mid - 1 ) > -1  ? arr[mid - 1]: -1;
//  console.log(`${arr[mid]} <= ${target} < ${next}`)
  if(arr[mid] >= target && prev < target){
    return mid;
  } else if(arr[mid] > target){
    return bs(arr.slice(0, mid), target);
  } else if(arr[mid] < target){
    let sub = bs(arr.slice(mid + 1), target);
     return sub > 0 ? sub + 1 + mid : -1;
  }
}