let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  let curLine = 0
  const T = parseInt(lines[curLine++])
  for (let t = 0; t < T; t++) {
    const [n, c0, c1, h] = lines[curLine++].split(' ').map((x) => parseInt(x))
    const p0 = Math.min(c0, h + c1)
    const p1 = Math.min(c1, h + c0)
    let ans = 0
    lines[curLine++].trim().split('').forEach((c) => ans += c === '1' ? p1 : p0)
    console.log(ans)
  }
})

var sizeOfData = readline();
for (var dataI = 0; dataI < sizeOfData; dataI++) {
    var secondLine = readline().split(' ');
    var n = secondLine[0], c0 = secondLine[1], c1 = secondLine[2], h = secondLine[3];
    var str = readline();
    var am0 = 0;
    var am1 = 0;
    for (var c of str) {
        if (c == '0') {
            am0++;
        } else if (c == '1') {
            am1++;
        }
    }
    var normprice = am0*c0 + am1*c1;
    var c0price = am0*h + am1*c1 + am0*c1;
    var c1price = am1*h + am0*c0 + am1*c0;
    print(Math.min(normprice, c0price, c1price));
}

var tc = parseInt(readline());

while(tc--){
    var arr = readline().split(' ').map(x => parseInt(x));
    var n = arr[0];
    var c0 = arr[1];
    var c1 = arr[2];
    var h = arr[3];

    var s = readline();

    var one = 0;
    var zero = 0;
    for(var i = 0; i < n; i++){
        if(s[i]=='1')one++;
        else zero++;
    }

    var taka = 0;
    if(c0 < c1){
        taka = c0 * zero;
        if((h+c0)<=c1){
            taka += one * (h+c0);
        }else{
            taka += c1 * one;
        }
    }
    else if(c1 < c0){
        taka = c1 * one;
        if((h+c1)<=c0){
            taka += zero * (h+c1);
        }else{
            taka += c0 * zero;
        }
    }else{
        print(n*c0);
        continue;
    }

    print(taka);
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, 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);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [n, c0, c1, h] = readLine().split(" ").map(Number);
    const str = readLine();
    let [min, count0, count1, count] = [Infinity, 0, 0, 0];

    for (let i = 0; i < str.length; i++) {
      if (str[i] === "0") count0++;
      else count1++;
    }

    count = count0 * c0 + count1 * c1;
    min = Math.min(min, count);
    // all 0
    count = n * c0 + count1 * h;
    min = Math.min(count, min);
    // all 1
    count = n * c1 + count0 * h;
    min = Math.min(count, min);
    //  01
    count = 0;
    for (let i = 0; i < n; i++) {
      const char = str[i];
      if (i % 2 === 0) {
        if (char === "0") count += c0;
        else count += c0 + h;
      } else {
        if (char === "1") count += c1;
        else count += c1 + h;
      }
    }
    min = Math.min(min, count);
    //  10
    count = 0;
    for (let i = 0; i < n; i++) {
      const char = str[i];
      if (i % 2 === 0) {
        if (char === "1") count += c1;
        else count += c1 + h;
      } else {
        if (char === "0") count += c0;
        else count += c0 + h;
      }
    }
    min = Math.min(min, count);

    console.log(min);
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var c0 = one[1];
		var c1 = one[2];
		var h = one[3];
		var s = nextCharArray();
		var sum = 0;
		for(var j = 0; j < N; j++){
			if(s[j] == "0"){
				sum += Math.min(c0, c1 + h);
			}else{
				sum += Math.min(c1, c0 + h);
			}
		}
		output[i] = sum;
	}
	myout(myconv(output, 9));
}

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

let i = 1;
let t = 0;
let input1 = 0;

// untuk input per test > 1
readline.on('line', line => {
    if (i == 1) {
        // number of test case
        t = parseInt(line)
        i++;
    } else {
        if (i % 2 === 0) input1 = line;
        else solve(input1, line)

        if (i <= t*2) i++
        else readline.close()
    }
});

// =========== DEFAULT FORMAT END ==============
const countObj = (arr, val)  => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);

function solve(line1, line2) {
    // your code here
    const [n, c0, c1, h] = line1.split(' ').map(item => parseInt(item));
    const binaryS = line2.split('')
    const a = c1 * n + (countObj(binaryS, '0') * h);
    const b = c0 * n + (countObj(binaryS, '1') * h);
    const c = (c0 * countObj(binaryS, 0) + c1 * countObj(binaryS, 1))
    console.log(Math.min(a, b, c))
  }

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const h="local"===process.argv[2],a=t=>{if(h){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function p(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(p());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=p();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){h&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e,r,n]=i.default.nextNumbers(),o=i.default.nextCharacters(),s=o.filter((t=>"0"==t)).length,u=o.filter((t=>"1"==t)).length,l=(t,n)=>e*t+r*n,h=l(s,u),a=0;for(;s>0;)s--,u++,a+=n,h=[h,a+l(s,u)].min();for(s=o.filter((t=>"0"==t)).length,u=o.filter((t=>"1"==t)).length,a=0;u>0;)u--,s++,a+=n,h=[h,a+l(s,u)].min();i.default.puts(h)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, c0, c1, h] = io.nextNumbers()
//   let a = io.nextCharacters()
//
//   let nr0 = a.filter((x) => x == "0").length
//   let nr1 = a.filter((x) => x == "1").length
//
//   let cost = (zero: number, one: number) => {
//     return c0 * zero + c1 * one
//   }
//
//   let c = cost(nr0, nr1)
//
//   let ac = 0
//
//   while (nr0 > 0) {
//     nr0--
//     nr1++
//     ac += h
//
//     c = [c, ac + cost(nr0, nr1)].min()
//   }
//
//   nr0 = a.filter((x) => x == "0").length
//   nr1 = a.filter((x) => x == "1").length
//
//   ac = 0
//
//   while (nr1 > 0) {
//     nr1--
//     nr0++
//     ac += h
//
//     c = [c, ac + cost(nr0, nr1)].min()
//   }
//
//   io.puts(c)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

var tc = parseInt(readline());

while(tc--){
    var arr = readline().split(' ').map(x => parseInt(x));
    var n = arr[0];
    var c0 = arr[1];
    var c1 = arr[2];
    var h = arr[3];

    var s = readline();

    var one = 0;
    var zero = 0;
    for(var i = 0; i < n; i++){
        if(s[i]=='1')one++;
        else zero++;
    }

    var taka = 0;
    var change = 0;
    if(c0 < c1){
        taka = c0 * zero;
        if(h < c1){
            change += h*one;
            change += c0 * one;
            if(change < c1 * one)taka += change;

        }else{
            taka += c1 * one;
        }
    }
    else if(c1 < c0){
        taka = c1 * one;
        if(h < c0){
            change += h*zero;
            change += c1*zero;
            if(change < c0 * zero)taka += change;
        }else{
            taka += c0 * zero;
        }
    }else{
        print(n*c0);
        continue;
    }

    print(taka);
}

var tc = parseInt(readline());

while(tc--){
    var arr = readline().split(' ').map(x => parseInt(x));
    var n = arr[0];
    var c0 = arr[1];
    var c1 = arr[2];
    var h = arr[3];

    var s = readline();

    var one = 0;
    var zero = 0;
    for(var i = 0; i < n; i++){
        if(s[i]=='1')one++;
        else zero++;
    }

    var taka = 0;
    if(c0 < c1){
        taka = c0 * zero;
        if(h*one < c1*one){
            taka += h*one;
            taka += c0*one;
        }else{
            taka += c1*one;
        }
    }
    else if(c1 < c0){
        taka = c1 * one;
        if(h*zero < c0*zero){
            taka += h*zero;
            taka += c1*zero;
        }else{
            taka += c0*zero;
        }
    }else{
        print(n*c0);
        continue;
    }

    print(taka);
}


var n=+readline();
var t=readline().split(' ').map(function(v){return+v;});
var ans=-1e9;
for(var i=3;i<=n;i++){
	if(n%i===0){
		var k=n/i;
		for(var j=0;j<k;j++){
			var sum=0;
			for(var jj=j;jj<n;jj+=k){
				sum+=t[jj];
			}
			ans=Math.max(ans,sum);
		}
	}
}
print(ans);

Array.prototype.sum = function () {
	var total = 0, i = this.length;
	while (i--) total += this[i];
	return total;
}

;(function () {
	var n = +readline(),
		t = readline().split(' ').map(Number)
		k = 1, s = t.sum();

	while ( n/++k >= 3 )
		if (! (n%k))
			for (var i = 0; i < k; i++) {
				var ns = 0;
				for (var j = i; j < n; j += k) ns += t[j];
				if (ns > s) s = ns;
			}

	print(s);

}).call(this);

var n=+readline();
var t=readline().split(' ').map(function(v){return+v;});
var ans=-1e3;
for(var i=3;i<=n;i++){
	if(n%i===0){
		var k=n/i;
		for(var j=0;j<k;j++){
			var sum=0;
			for(var jj=j;jj<n;jj+=k){
				sum+=t[jj];
			}
			ans=Math.max(ans,sum);
		}
	}
}
print(ans);

Array.prototype.sum = function () {
	var total = 0, i = this.length;
	while (i--) total += this[i];
	return total;
}

Array.prototype.frequency = function (skip, startIndex) {
	var l = this.length, ret = [];
	for (var i = startIndex; i < l; i += skip + 1) ret.push(this[i]);
	return ret;
}

;(function () {
	var n = +readline();
	var t = readline().split(' ').map(Number);

	var s = t.sum();

	if (!(n % 2) && n > 5) {
		var k = 0;
		var q = n / (k + 1);
		while ( q > 3 ) {
			if (!(q % 1)) {
				for (var i = 0; i < q/2; i++) {
					var ns = t.frequency(i, k).sum();
					if (ns > s) s = ns;
				}
			}
			q = n / (++k + 1)
		}
	}

	print(s);

}).call(this);

Array.prototype.sum = function () {
	var total = 0, i = this.length;
	while (i--) total += this[i];
	return total;
}

Array.prototype.frequency = function (skip, startIndex) {
	var l = this.length, ret = [];
	for (var i = startIndex; i < l; i += skip + 1) ret.push(this[i]);
	return ret;
}

;(function () {
	var n = +readline();
	var t = readline().split(' ').map(Number);

	var s = t.sum();

	if (!(n % 2)) {
		var k = 0;
		var q = n / (k + 1);
		while ( q > 3 ) {
			if (!(q % 1)) {
				for (var i = 0; i < q/2; i++) {
					var ns = t.frequency(i, k).sum();
					if (ns > s) s = ns;
				}
			}
			q = n / (++k + 1)
		}
	}

	print(s);

}).call(this);


function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		if (a.y == 0 || b.y == 0) {
			if (a.y == 0 && b.y == 0) {
				return Math.abs(a.x) - Math.abs(b.x);
			}
			if (a.y == 0) {
				return -1;
			}
			return 1;
		}
		if (a.x == b.x) {
			return Math.abs(a.y) - Math.abs(b.y);
		}
		return a.x - b.x;
	});
	var moves = [];
	for (var i = 0; i < numBombs; ++i) {
		var bomb = bombs[i], x = bomb.x, y = bomb.y;
		if (x == 0) {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
			moves.push('3');
			continue;
		}
		if (x < 0) {
			var left = 'L', right = 'R';
		} else {
			var left = 'R', right = 'L';
		}
		moves.push('1 '+Math.abs(x)+' '+left);
		if (y == 0) {
			moves.push('2');
		} else {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
		}
		moves.push('1 '+Math.abs(x)+' '+right);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		return Math.abs(a.x) + Math.abs(a.y) - Math.abs(b.x) - Math.abs(b.y);
	});
	var moves = [];
	function move(x0, y0, x1, y1) {
		if (x0 != x1) {
			moves.push('1 '+Math.abs(x0-x1)+' '+(x0 < x1 ? 'R' : 'L'));
		}
		if (y0 != y1) {
			moves.push('1 '+Math.abs(y0-y1)+' '+(y0 < y1 ? 'U' : 'D'));
		}
	}
	for (var i = 0; i < numBombs; ++i) {
		var x = bombs[i].x, y = bombs[i].y;
		move(0, 0, x, y);
		moves.push('2');
		move(x, y, 0, 0);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		if (a.y == 0 || b.y == 0) {
			if (a.y == 0 && b.y == 0) {
				return a.x - b.x;
			}
			if (a.y == 0) {
				return -1;
			}
			return 1;
		}
		if (a.x == b.x) {
			return Math.abs(a.y) - Math.abs(b.y);
		}
		return a.x - b.x;
	});
	var moves = [];
	for (var i = 0; i < numBombs; ++i) {
		var bomb = bombs[i], x = bomb.x, y = bomb.y;
		if (x == 0) {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
			moves.push('3');
			continue;
		}
		if (x < 0) {
			var left = 'L', right = 'R';
		} else {
			var left = 'R', right = 'L';
		}
		moves.push('1 '+Math.abs(x)+' '+left);
		if (y != 0) {
			moves.push('2');
		} else {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
		}
		moves.push('1 '+Math.abs(x)+' '+right);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		if (a.y == 0 || b.y == 0) {
			if (a.y == 0 && b.y == 0) {
				return a.x - b.x;
			}
			if (a.y == 0) {
				return -1;
			}
			return 1;
		}
		if (a.x != b.x) {
			return a.x - b.x;
		}
		return b.y - a.y;
	});
	var moves = [];
	for (var i = 0; i < numBombs; ++i) {
		var bomb = bombs[i], x = bomb.x, y = bomb.y;
		if (x == 0) {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
			moves.push('3');
			continue;
		} else if (x < 0) {
			var left = 'L', right = 'R';
		} else {
			var left = 'R', right = 'L';
		}
		moves.push('1 '+Math.abs(x)+' '+left);
		if (y == 0) {
			moves.push('2');
		} else {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
		}
		moves.push('1 '+Math.abs(x)+' '+right);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		if (a.y == 0 || b.y == 0) {
			if (a.y == 0 && b.y == 0) {
				return a.x - b.x;
			}
			if (a.y == 0) {
				return -1;
			}
			return 1;
		}
		if (a.x != b.x) {
			return a.x - b.x;
		}
		return a.y - b.y;
	});
	var moves = [];
	for (var i = 0; i < numBombs; ++i) {
		var bomb = bombs[i], x = bomb.x, y = bomb.y;
		if (x == 0) {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
			moves.push('3');
			continue;
		} else if (x < 0) {
			var left = 'L', right = 'R';
		} else {
			var left = 'R', right = 'L';
		}
		moves.push('1 '+Math.abs(x)+' '+left);
		if (y == 0) {
			moves.push('2');
		} else {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
		}
		moves.push('1 '+Math.abs(x)+' '+right);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		points = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		points.push({ x: x, y: y });
	}
	points.sort(function (a, b) {
		if (a.y == 0 || b.y == 0) {
			if (a.y == 0 && b.y == 0) {
				return a.x - b.x;
			}
			if (a.y == 0) {
				return a;
			}
			return b;
		}
		if (a.x != b.x) {
			return a.x - b.x;
		}
		return a.y - b.y;
	});
	var moves = [];
	for (var i = 0; i < numBombs; ++i) {
		var point = points[i], x = point.x, y = point.y;
		if (x == 0) {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
			moves.push('3');
			continue;
		} else if (x < 0) {
			var left = 'L', right = 'R';
		} else {
			var left = 'R', right = 'L';
		}
		moves.push('1 '+Math.abs(x)+' '+left);
		if (y == 0) {
			moves.push('2');
		} else {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
		}
		moves.push('1 '+Math.abs(x)+' '+right);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		if (a.y == 0 || b.y == 0) {
			if (a.y == 0 && b.y == 0) {
				return a.x - b.x;
			}
			if (a.y == 0) {
				return -1;
			}
			return 1;
		}
		if (a.x == b.x) {
			return Math.abs(a.y) - Math.abs(b.y);
		}
		return a.x - b.x;
	});
	var moves = [];
	for (var i = 0; i < numBombs; ++i) {
		var bomb = bombs[i], x = bomb.x, y = bomb.y;
		if (x == 0) {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
			moves.push('3');
			continue;
		}
		if (x < 0) {
			var left = 'L', right = 'R';
		} else {
			var left = 'R', right = 'L';
		}
		moves.push('1 '+Math.abs(x)+' '+left);
		if (y == 0) {
			moves.push('2');
		} else {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
		}
		moves.push('1 '+Math.abs(x)+' '+right);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		if (a.y == 0 || b.y == 0) {
			if (a.y == 0 && b.y == 0) {
				return a.x - b.x;
			}
			if (a.y == 0) {
				return -1;
			}
			return 1;
		}
		if (a.y != b.y) {
			return a.y - b.y;
		}
		return a.x - b.x;
	});
	var moves = [];
	for (var i = 0; i < numBombs; ++i) {
		var bomb = bombs[i], x = bomb.x, y = bomb.y;
		if (x == 0) {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
			moves.push('3');
			continue;
		} else if (x < 0) {
			var left = 'L', right = 'R';
		} else {
			var left = 'R', right = 'L';
		}
		moves.push('1 '+Math.abs(x)+' '+left);
		if (y == 0) {
			moves.push('2');
		} else {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
		}
		moves.push('1 '+Math.abs(x)+' '+right);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		if (a.y == 0 || b.y == 0) {
			if (a.y == 0 && b.y == 0) {
				return a.x - b.x;
			}
			if (a.y == 0) {
				return -1;
			}
			return 1;
		}
		if (a.x != b.x) {
			return a.x - b.x;
		}
		return Math.abs(a.y) - Math.abs(b.y);
	});
	var moves = [];
	for (var i = 0; i < numBombs; ++i) {
		var bomb = bombs[i], x = bomb.x, y = bomb.y;
		if (x == 0) {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
			moves.push('3');
			continue;
		} else if (x < 0) {
			var left = 'L', right = 'R';
		} else {
			var left = 'R', right = 'L';
		}
		moves.push('1 '+Math.abs(x)+' '+left);
		if (y == 0) {
			moves.push('2');
		} else {
			if (y > 0) {
				var up = 'U', down = 'D';
			} else {
				var up = 'D', down = 'U';
			}
			moves.push('1 '+Math.abs(y)+' '+up);
			moves.push('2');
			moves.push('1 '+Math.abs(y)+' '+down);
		}
		moves.push('1 '+Math.abs(x)+' '+right);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numBombs = parseInt(readline()),
		bombs = [];
	for (var i = 0; i < numBombs; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], y = data[1];
		bombs.push({ x: x, y: y });
	}
	bombs.sort(function (a, b) {
		return Math.abs(a.x) + Math.abs(a.y) - Math.abs(b.x) - Math.abs(b.y);
	});
	var moves = [];
	function move(x0, y0, x1, y1) {
		if (x0 != x1) {
			moves.push('1 '+Math.abs(x0-x1)+' '+(x0 < x1 ? 'L' : 'R'));
		}
		if (y0 != y1) {
			moves.push('1 '+Math.abs(y0-y1)+' '+(y0 < y1 ? 'D' : 'U'));
		}
	}
	for (var i = 0; i < numBombs; ++i) {
		var x = bombs[i].x, y = bombs[i].y;
		move(0, 0, x, y);
		moves.push('2');
		move(x, y, 0, 0);
		moves.push('3');
	}
	print(moves.length);
	print(moves.join('\n'));
}

main();


;(function () { // 362B

	print(function (n, m) {
		if (m === 0) return 'YES';
		var d = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }), dl = d.length;
		if (d[0] === 1 || d[dl - 1] === n) return 'NO';
		for (var i = 2, k = 0; i < dl; i++)
			if ( d[i] === d[i-1] + 1 && d[i] === d[i-2] + 2 ) return 'NO';
		return 'YES';
	}.apply(null, readline().split(' ').map(Number)));

}).call(this);

print(function(n, m) {
	if (m === 0) return 'YES';

	var d = readline().split(' ').map(Number).sort(function(a, b) {
		return a - b;
	});

	if (d[m - 1] === n || d[0] === 1) return 'NO';

	for (var i = 2; i < m; i++)
		if (d[i] - d[i - 2] === 2) return 'NO';

	return 'YES';

} .apply(0, readline().split(' ').map(Number)));

print(function(n, m) {
	if (m === 0) return 'YES';

	var d = readline().split(' ').map(Number).sort(function(a, b) {
		return a - b;
	});

	if (d[m - 1] === n) return 'NO';

	for (var i = 2; i < m; i++)
		if (d[i] - d[i - 2] === 2) return 'NO';

	return 'YES';

} .apply(0, readline().split(' ').map(Number)));

print(function(n, m) {
	if (m === 0) return 'NO';

	var d = readline().split(' ').map(Number).sort(function(a, b) {
		return a - b;
	});

	if (d[m - 1] === n) return 'NO';

	for (var i = 2; i < m; i++)
		if (d[i] - d[i - 2] === 2) return 'NO';

	return 'YES';

} .apply(0, readline().split(' ').map(Number)));

;(function () { // 362B

	print(function (n, m) {
		var d = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }), dl = d.length;
		if (d[0] === 1 && d[dl - 1] === n) return 'NO';
		for (var i = 2, k = 0; i < dl; i++)
			if ( d[i] === d[i-1] + 1 && d[i] === d[i-2] + 2 ) return 'NO';
		return 'YES';
	}.apply(null, readline().split(' ').map(Number)));

}).call(this);


var n = parseInt(readline());
var x = readline().split(' ');
var a = []
for(var i = 0;i < n; i++) {
    a[i] = parseInt(x[i]);
}
var ans = Math.abs(a[0]);
for(var i=1;i<n;i++) {
    ans += Math.abs(a[i] - a[i-1]);
}
print(ans);

'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 toIntArr(arr) {
    const r = arr.map((item) => {
        return parseInt(item);
    });

    return r;
}

////////////////////////////////

function main() {
    let n = parseInt(readline());
    let arr = toIntArr(readline().split(' '));

    let r = 0;
    let p = 0;

    for (let i = 0; i < n; i++) {
        r += Math.abs(arr[i] - p);
        p = arr[i];
    }

    console.log(r);
}

function rda(){ return readline().split(" ").map(Number); }
function rdn(){ return Number(readline()); }

var n = rdn(), b = rda();

var ans = 0;
var now = 0;
for(var i = 0; i < n; i++){
    if(now < b[i]){
        ans += b[i] - now;
        now = b[i];
    }else if(now > b[i]){
        ans += now - b[i];
        now = b[i];
    }else{
        continue;
    }
}

write(ans);

var n = parseInt(readline());
var a = readline().split(" ").map(Number);
var ans = 0;
var x = 0;

for (var i = 0; i < n; i++) {
	if (x != a[i]) {
		ans += Math.abs(a[i]-x);
		x = a[i];
	}
}

print(ans);

n = +readline();
a = readline().split(" ").map(Number);
var res = 0 , add = 0;
for (i = 0 ; i < n ; i ++){
    a[i] -= add;
    add += a[i];
    res += Math.abs(a[i]);

}

write(res);

var n = parseInt(readline());
var x = readline().split(' ');
var a = []
for(var i = 0;i < n; i++) {
    a[i] = parseInt(x[i]);
}
var ans = a[0];
for(var i=1;i<n;i++) {
    ans += Math.abs(a[i] - a[i-1]);
}
print(ans);

'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 toIntArr(arr) {
    const r = arr.map((item) => {
        return parseInt(item);
    });

    return r;
}

////////////////////////////////

function main() {
    let n = parseInt(readline());
    let arr = toIntArr(readline().split(' '));

    let r = 0;
    let k = 0;

    for (let i = 1; i < n; i++) {
        r += Math.abs(arr[i] - k);
        k = arr[i];
    }

    console.log(r);
}


let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split("\n").filter(data => {
    return data.length > 0
});
txt.shift();

txt.forEach(data => {
    let info = data.split(" ");
    payment(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1);
});

function payment(a, b, n, s) {
    if (b >= s) {
        console.log("YES");
        return;
    } else {
        let r = Math.floor(s / n);
        if(r>a){
            if (a * n + b < s) {
                console.log("NO");
            } else {
                console.log("YES");
            }
        }else{
            if (r * n == s) {
                console.log("YES");
            } else {
                if (r * n + b < s) {
                    console.log("NO");
                } else {
                    console.log("YES");
                }
            }
        }
    }
}

  var lines = parseInt(readline(), 10);

  function min(a, b) {
    return a < b ? a : b;
  }

  for (var i = 0; i < lines; i++) {
    var tmpArr = readline()
      .split(" ")
      .map(function(val) {
        return parseInt(val, 10);
      });
    var a = tmpArr[0];
    var b = tmpArr[1];
    var n = tmpArr[2];
    var S = tmpArr[3];

    var maxA = Math.floor(S / n);
    var tail = S - min(maxA, a) * n;
    print(tail > b ? "NO": "YES");
  }

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	let q = nl.num();
  let ans = [];
  for(let i = 0; i < q; i++){
    let [a, b, n, s] = nl.nums();
    let an = Math.trunc(s/n);
    let x = ((an < a)?an:a)*n;
    ans.push((x + b) >= s?"YES":"NO");
  }
	console.log(ans.join('\n'));

};

process.stdin.on('end', sol);

//A. Payment Without Change
var attempts = Number(readline());
var PaymentWithoutChange = () => {
    do {
        attempts--;
        var numbers = readline().split(' ').map(x => Number(x));
        var a = numbers[0], b = numbers[1], n = numbers[2], s = numbers[3];
        if ((a * n) + b >= s) {
            var a_needed = Math.floor(s / n);
            // var b_rem = s % n;
            if (a_needed > a && b >= s - a * n || a_needed < a && b >= s - a_needed * n || a_needed == a)
                print('YES');
            else
                print('NO');
        }
        else
            print('NO');

    } while (attempts > 0);
}
PaymentWithoutChange();

function main() {
  var testCasesNum = +readline();
  var testCases = [];
  for (var i = 0; i < testCasesNum; i++) {
    (function (i) {
      testCases[i] = readline();
      canPay(testCases[i]);
    })(i)
  }
}

function canPay(testCase) {
  var caseArr = testCase.split(' ').map(Number);
  print(Math.min(caseArr[0] * caseArr[2], Math.floor(caseArr[3] / caseArr[2]) * caseArr[2]) + caseArr[1] >= caseArr[3] ? 'YES' : 'NO');
}
main();

//DONE:
process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const q = parseInt(arr.shift())

  for(let i = 0; i < q; i++) {
    const arrq = arr[i].split(' ')
    const a = arrq[0],
      b = arrq[1],
      n = arrq[2],
      s = arrq[3]

    const ax = Math.min(a, Math.floor(s / n))
    if(s - ax * n <= b) 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;
});

const readline = () => {
    return inputString[currentLine++];
}

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

const main = () => {
    let q = parseInt(readline());
    let ans = '';
    for (let i = 0; i < q; i++) {
        let [a, b, n, s] = readline().split(' ').map(Number);
        const h = Math.min(Math.floor(s / n), a);
        const bk = s - (n * h);
        if (bk <= b) {
            ans += "YES\n";
        } else {
            ans += "NO\n";
        }
        // console.log(h, bk);
        // console.log(a,b,n,s);
    }
    console.log(ans);
}

let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

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

function main() {
	let t = readLine() >> 0;

	while (t--) {
		let [a, b, n, s] = readLine()
			.split(' ')
			.map(x => x >> 0);

		let ta = Math.floor(s / n);
		let tn;

		if (ta <= a) {
			tn = ta * n;
		} else {
			tn = a * n;
		}

		if (s - tn <= b) {
			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();}); function readLine() { return inputString[currentLine++];}

//please ignore the lines above this

function main() {
    let noOftestCases = +(readLine());

    while(noOftestCases--)
    {

         let inp = readLine();
         var testCases = inp.split(" ");
        let noCoinsN = testCases[0];
        let noCoins1 = testCases[1];
        let ValueN = testCases[2];
        let total = testCases[3];

        let biggestValuewithN = Math.floor(total/ValueN);

        let maxValuePossible = Math.min(biggestValuewithN,noCoinsN)*ValueN;

        let noOf1coinsreq = total - maxValuePossible;

        if(noOf1coinsreq <= noCoins1 )
        {
            console.log("YES");
        }
        else { console.log("NO");

    }
}
}

'use strict'

const problem = (a, b, n, S) => (S - (Math.min(S/n|0, a))*n <= b) ? 'YES' : 'NO'
let q = +readline();

while(q--) {
    const abnS = readline().split(' ').map(Number);
    print(problem(abnS[0], abnS[1], abnS[2], abnS[3]));
}

function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){print(t);}//standard output
function myerr(t){console.log(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main() {
  var N = myconv(readline(),1);
  var output = [];
  for(var i = 1; i <= N; i++){
    var tmp = myconv(readline(),4);
    var a = tmp[0];
    var b = tmp[1];
    var n = tmp[2];
    var S = tmp[3];
    var other;//bの必要分
    if(S >= a * n){
       other = S - a * n;
    }else{
       other = S % n;
    }
    if(other - b <= 0){
       output.push("YES");
    }else{
      output.push("NO");
    }
  }
  myout(output.join("\n"));
}

Main();

'use strict'
 let n = readline();
for( let i=0;i<n;i++)
{
    isok();
}
function isok()
{
    var a = readline().split(' ').map(Number);
    var ans=0;
    ans+=(Math.min(a[0],Math.trunc(a[3]/a[2]))*a[2]);
    if(a[3]-ans<=a[1])print('YES');
    else print('NO');
}

'use strict'
let input = readline();
while(input > 0) {
    const abnS = readline().split(' ').map(Number);
    print(calculate(abnS));
    input--
}
function calculate(input){
    let a = input[0];
    let b = input[1];
    let n = input[2];
    let s = input[3];
    let div = Math.trunc(s/n);
    let multi = a < div ? n * a : div * n;
    let diff  = s - multi;
    if(diff <= b){
        return "YES";
    }else return "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();}); function readLine() { return inputString[currentLine++];}

//please ignore the lines above this

function main() {
    let noOftestCases = +(readLine());

    while(noOftestCases--)
    {

         let inp = readLine();
         var testCases = inp.split(" ");
        let noCoinsN = testCases[0];
        let noCoins1 = testCases[1];
        let ValueN = testCases[2];
        let total = testCases[3];

        let biggestValuewithN = total/ValueN;

        let maxValuePossible = Math.min(biggestValuewithN,noCoinsN)*ValueN;

        let noOf1coinsreq = total - maxValuePossible;

        if(noOf1coinsreq > noCoins1 )
        {
            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();}); function readLine() { return inputString[currentLine++];}

//please ignore the lines above this

function main() {
    let noOftestCases = +(readLine());

    while(noOftestCases--)
    {

         let inp = readLine();
         var testCases = inp.split(" ");
        let noCoinsN = testCases[0];
        let noCoins1 = testCases[1];
        let ValueN = testCases[2];
        let total = testCases[3];

        let biggestValuewithN = total/ValueN;

        let maxValuePossible = Math.min(biggestValuewithN,noCoinsN)*ValueN;

        let noOf1coinsreq = total - maxValuePossible;

        if(noOf1coinsreq < noCoins1 )
        {
            console.log("YES");
        }
        else { console.log("NO");

    }
}
}

let fs = require("fs")

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
})
txt.shift()

txt.forEach(element => {
    let info = element.split(" ")
    football(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1)
});

function football(a, b, n, s) {
    if (a * n == s) {
        console.log("YES");
    } else if (a * n < s) {
        if (a * n + b < s) {
            console.log("NO");
        } else {
            console.log("YES");
        }
    } else {
       console.log("YES");

    }
}

let fs = require("fs")

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
})
txt.shift()

txt.forEach(element => {
    let info = element.split(" ")
    football(info[0] * 1, info[1] * 1, info[2] * 1, info[3] * 1)
});

function football(a, b, n, s) {
    if (a * n == s) {
        console.log("YES");
    } else if (a * n < s) {
        if (a * n + b < s) {
            console.log("NO");
        } else {
            console.log("YES");
        }
    } else {
       for (let index = a; index >0; index--) {
           if(index*n==s){
            console.log("YES");
            return;
           }else if(index*n<s && index*n+b>=s){
            console.log("YES");
            return;
           }
       }
       console.log("NO");
    }
}

function payment(a,b,n,s){
    if(b>=s){
        console.log("YES")
        return;
    }else{
        let total=0;
        for(let i=0;i<a;i++){
            total+=a*n;
            if(total==s){
                console.log("YES")
                return;
            }else if(total>s){
                total-=a*n;
                if(total+b<s){
                    console.log("NO")
                }else{
                    console.log("YES")
                }
                return;
            }
        }
        if(total+b<s){
            console.log("NO")
        }else{
            console.log("YES")
        }

    }
}

let fs=require('fs');
let txt=fs.readFileSync(0,"utf-8").split("\n").filter(data=>{return data.length>0});
txt.shift();

txt.forEach(data=>{
    let info=data.split(" ");
    payment(info[0]*1,info[1]*1,info[2]*1,info[3]*1);
});
function payment(a,b,n,s){
    if(b>=s){
        console.log("YES");
        return;
    }else{
        let total=0;
        for(let i=0;i<a;i++){
            total+=a*n;
            if(total==s){
                console.log("YES");
                return;
            }else if(total>s){
                total-=a*n;
                if(total+b<s){
                    console.log("NO");
                }else{
                    console.log("YES");
                }
                return;
            }
        }
        if(total+b<s){
            console.log("NO");
        }else{
            console.log("YES");
        }

    }
}

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	let q = nl.num();
  let ans = [];
  for(let i = 0; i < q; i++){
    let [a, b, n, s] = nl.nums();
    let an = Math.trunc(s/n);
    let bn = (an < a)?s%n:s-(a*n);
    ans.push((an >= a && bn <= b)?"YES":"NO");
  }
	console.log(ans.join('\n'));

};

process.stdin.on('end', sol);

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	let q = nl.num();
  let ans = [];
  for(let i = 0; i < q; i++){
    let [a, b, n, s] = nl.nums();
    let an = Math.trunc(s/n);
    let bn = (an < a)?s%n:s-(a*n);
    ans.push((an <= a && bn <= b)?"YES":"NO");
  }
	console.log(ans.join('\n'));

};

process.stdin.on('end', sol);

'use strict'
 let n = readline();
while(n>0)
{
    isok();
     n--
}
function isok()
{
    var a = readline().split(' ').map(Number);
    var ans=0;
    ans+=(Math.min(a[0],a[3]/a[2])*a[2]);
    if(a[3]-ans<=a[1])print('YES');
    else print('NO');
}

'use strict'
let input = readline();
while(input > 0) {
    const abnS = readline().split(' ').map(Number);
    print(calculate(abnS));
    input--
}
function calculate(input){
    let a = input[0];
    let b = input[1];
    let n = input[2];
    let s = input[3];
    if(a * n <= s && (s - (a * n)) <= b){
        return "YES";
    }else return "NO";
}

'use strict'
let input = readline();
while(input > 0) {
    const abnS = readline().split(' ').map(Number);
    print(calculate(abnS));
    input--
}
function calculate(input){
    let a = input[0];
    let b = input[1];
    let n = input[2];
    let s = input[3];
    if((a * n) <= s && (s - (a * n)) <= b){
        return "YES";
    }else return "NO";
}

//A. Payment Without Change
var attempts = Number(readline());
var PaymentWithoutChange = () => {
    do {
        attempts--;
        var numbers = readline().split(' ').map(x => Number(x));
        var a = numbers[0], b = numbers[1], n = numbers[2], s = numbers[3];
        if ((a * n) + b >= s) {
            var a_needed = Math.floor(s / n);
            var b_rem = s % n;
            if (a_needed <= a && b_rem <= b || b>= s-a*n)
                print('YES');
            else
                print('NO');
        }
        else
            print('NO');

    } while (attempts > 0);
}
PaymentWithoutChange();

//A. Payment Without Change
var attempts = Number(readline());
var PaymentWithoutChange = () => {
    do {
        attempts--;
        var numbers = readline().split(' ').map(x => Number(x));
        var a = numbers[0], b = numbers[1], n = numbers[2], s = numbers[3];
        if ((a * n) + b >= s) {
            var a_needed = Math.floor(s / n);
            var b_rem = s % n;
            if (a_needed <= a && b_rem <= b || b>=a*n)
                print('YES');
            else
                print('NO');
        }
        else
            print('NO');

    } while (attempts > 0);
}
PaymentWithoutChange();

//A. Payment Without Change
var attempts = Number(readline());
var PaymentWithoutChange = () => {
    do {
        attempts--;
        var numbers = readline().split(' ').map(x => Number(x));
        var a = numbers[0], b = numbers[1], n = numbers[2], s = numbers[3];
        if ((a * n) + b >= s) {
            var a_needed = Math.floor(s / n);
            var b_rem = s % n;
            if (a_needed <= a && b_rem <= b)
                print('YES');
            else
                print('NO');
        }
        else
            print('NO');

    } while (attempts > 0);
}
PaymentWithoutChange();


'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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function Queue() {
    this.length = 0;
}

Queue.prototype.push = function (item) {
  var node = {item: item};
  if (this.last) {
    this.last = this.last.next = node;
  } else {
    this.last = this.first = node;
  }
  this.length++;
};

Queue.prototype.shift = function () {
  var node = this.first;
  if (node) {
    this.first = node.next;
    if (!(--this.length)) {
      this.last = undefined;
    }
    return node.item;
  }
};

Queue.prototype.slice = function (start, end) {
  start = typeof start === 'undefined' ? 0 : start;
  end = typeof end === 'undefined' ? Infinity : end;

  var output = [];

  var i = 0;
  for (var node = this.first; node; node = node.next) {
    if (--end < 0) {
      break;
    } else if (++i > start) {
      output.push(node.item);
    }
  }
  return output;
}

class Logger {

  constructor() {
    this.enabled = false;
  }

  enable() {
    this.enabled = true;
  }

  disable() {
    this.enabled = false;
  }

  log(...str) {
    if (this.enabled) {
      console.error(...str);
    }
  }
}

let logger = new Logger();
// logger.enable();

function main() {

  let t = +readline();

  let a = 0;

  let dfs = (array, max) => {
    let res = [];

    let stack = [];
    for (let i = array[0][0]; i <= array[0][1]; ++i) {
      stack.push([i]);
    }

    while(stack.length > 0) {
      ++a;
      logger.log("stack:", stack)
      let current = stack.pop();
      let arrayIndex = current.length;

      // logger.log(current, max, arrayIndex);
      // logger.log(array[arrayIndex]);

      if (arrayIndex >= max) {
        res = current;
        break;
      }

      for (let i = array[arrayIndex][0]; i <= array[arrayIndex][1]; ++i) {
        if (current.includes(i)) continue;
        let newelem = current.slice(0)
        newelem.push(i);
        // logger.log("newelem : ",newelem)
        stack.push(newelem);
      }
    }

    return res;
  }

  for (let i = 0; i < t; ++i) {
    let n = +readline();
    let array = [];

    // Register inputs
    for (let j = 0; j < n; ++j) {
      let [l, r] = readline().split(' ').map((a) => +a);
      array.push([l, r])
    }

    logger.log(array);
    array.sort((a,b) => {
      return (a[1]-a[0])-(b[1]-b[0]);
    })
    logger.log(array)

    let res = dfs(array, n)

    for (let i = 0; i < array.length; ++i) {
      console.log(array[i][0], array[i][1], res[i]);
    }
    console.log()

  }

  logger.log(a);

}

const solve = (arr1)=>{
   let arr = [...arr1],obj={},obj1 = {};
     arr.sort((a,b)=>Math.abs(a[0]-a[1]) - Math.abs(b[0]-b[1]));
     for(let i=0;i<arr.length;i++){
          if(arr[i][0]===arr[i][1]) {
               obj[arr[i]] = arr[i][0];
               obj1[arr[i][0]] = 1;
          }
          else{
               for(let j=arr[i][0];j<=arr[i][1];j++)
                    if(!obj1[j]){
                         obj1[j] = 1;
                         obj[arr[i]] = j;
                         break;
                    }
          }
     }
     for(let i=0;i<arr1.length;i++){
          let res = arr1[i].reduce((s,r)=>s+r+" ","")+obj[arr1[i]];
          console.log(res);
     }
}

function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = [];
       for(let j=0;j<n;j++)
          arr.push(readline().trim().split(" ").map(cur=>parseInt(cur)));
       solve(arr);
  }
}
main();

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const rng = [];
		for (let i = 0; i < n; i++) {
			rng.push([...rna(), i]);
		}

		rng.sort(comp);
		function comp (x, y) {
			if (x[0] == y[0])
				return y[1] - x[1];
			else
				return x[0] - y[0];
		}
		rng.push([INF, INF, INF]);

		for (let i = 0; i < n; i++) {
			const [l, r, indx] = rng[i];
			const [lnxt, rnxt, indxnxt] = rng[i+1];
			if (lnxt == l)
				console.log(l, r, rnxt + 1);
			else
				console.log(l, r, l);
		}
		console.log('');
	}
}

const lib = require('readline');
const rl = lib.createInterface({
    input: process.stdin,
    output: process.stdout
});

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

let solve = async () => {
  const nsc = parseInt(await getLine());
  for(let sc = 0; sc < nsc; sc++) {
      if (sc > 0)
          console.log('');
      const n = parseInt(await getLine());
      const segs = new Array(n);
      for(let i = 0; i < n; i++) {
          const [l, r] = (await getLine()).split(' ').map(num => parseInt(num));
          segs[i] = {
              l, r
          }
      }
     segs.sort((a,b) => (a.r-a.l) - (b.r-b.l));
     for(let i = 0; i < segs.length; i++) {
         const cur = segs[i];
         let a = undefined, b = undefined;
         if (cur.l === cur.r) {
             console.log(`${cur.l} ${cur.r} ${cur.l}`);
         } else {
             for(let j = 0; j < i; j++) {
                 if (!segs[j].used && segs[j].l >= cur.l && segs[j].r <= cur.r) {
                     if (!a) a = segs[j];
                     else {
                         b = segs[j];
                         break;
                     }
                 }
             }
             a.used = true;
             if (b)
                 b.used = true;
            if (!b) {
               if (a.l > cur.l) {
                   console.log(`${cur.l} ${cur.r} ${cur.l}`);
               } else {
                   console.log(`${cur.l} ${cur.r} ${cur.r}`);
               }
            } else {
                if (a.l < b.l) {
                    console.log(`${cur.l} ${cur.r} ${a.r + 1}`);
                } else {
                    console.log(`${cur.l} ${cur.r} ${b.r + 1}`);
                }
            }
         }
     }
  }
}

solve();


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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const n = parseInt(arr.shift())

  for(let i = 0; i < n; i++) {
    const [c, s] = arr[i].split(' ').map(a => parseInt(a))
    let cost = 0
    if(s > c) {
      let mod = s % c
      let div = Math.floor(s / c)
      cost += (div ** 2) * (c - mod)
      cost += ((div + 1) ** 2 ) * mod
    }
    else {
      cost += s
    }
    wr(cost)
  }
})

function wr(...x) {
  console.log(...x)
}

function max(...x) {
  return Math.max(...x)
}

function min(...x) {
  return Math.min(...x)
}

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [c, s] = line.split(' ');
            const k = s / c << 0;
            const m = s - k * c;
            console.log(((k + 1) ** 2) * m + (k **2) * (c - m));
        });
});

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [radiators, minSections] = line.split(' ').map(Number);
            const solution = new Array(radiators);
            solution.fill(0);
            let sections = 0;
            while(sections < minSections) {
                for (let i = 0; i < radiators && sections < minSections; i++) {
                    solution[i] += 1;
                    sections += 1;
                }
            }
            console.log(solution.map(v => v*v).reduce((sum, v) => sum + v, 0));
        });
});

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [r, s] = line.split(' ').map(Number);
             // Math.floor replaced with << operator
            console.log(((s / r) << 0) * ((s / r) << 0) * (r - (s - ((s / r) << 0) * r)) + (((s / r) << 0) + 1) * (((s / r) << 0) + 1) * (s - ((s / r) << 0) * r));
        });
});

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [radiators, minSections] = line.split(' ').map(Number);
            const v = Math.floor(minSections / radiators);
            const vPlus1Number = minSections - v * radiators;
            const vNumber = radiators - vPlus1Number;
            const result = v * v * vNumber + (v + 1) * (v + 1) * vPlus1Number;
            console.log(result);
        });
});

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [c, s] = line.split(' ').map(Number);
            const k = s / c << 0;
            const m = s - k * c;
            console.log(((k + 1) ** 2) * m + (k **2) * (c - m));
        });
});

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [radiators, minSections] = line.split(' ').map(Number);
            const v = (minSections / radiators) << 0; // Math.floor
            const result = v * v * (radiators - (minSections - v * radiators)) + (v + 1) * (v + 1) * (minSections - v * radiators);
            console.log(result);
        });
});

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [r, m] = line.split(' ').map(Number);
            console.log(Math.floor(m / r) * Math.floor(m / r) * (r - (m - Math.floor(m / r) * r)) + (Math.floor(m / r) + 1) * (Math.floor(m / r) + 1) * (m - Math.floor(m / r) * r));
        });
});

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [radiators, minSections] = line.split(' ').map(Number);
            const solution = new Array(radiators);
            const startValue = Math.floor(minSections / radiators);
            solution.fill(startValue);
            let sections = startValue * radiators;
            for (let i = 0; i < radiators && sections < minSections; i++) {
                solution[i] += 1;
                sections += 1;
            }
            console.log(solution.map(v => v * v).reduce((sum, v) => sum + v, 0));
        });
});

'use strict'
 let n = readline();
for( let i=0;i<n;i++)
{
    isok();
}
function isok()
{
    var a = readline().split(" ").map(Number);
    var id=Math.trunc(a[1]/a[0]);
    var les=(a[1]%a[0]);
    let ok  = a[0]-les;
    let ans = id*id*ok;
    id+=1;
    ans+= (id*id*les);
    print(ans);

}

var n = Number(readline);
for( i=0;i<n;i++)
{
    print(isok());
}
function isok()
{
    var a=readline().split(" ").map(l>=Number(l));
    var id=a[1]/a[0];
    var les=(a[1]%a[0]);
    ok  = a[0]-les;
    ans = id*id*ok;
    id++;
    ans+= (id*id*les);
    return ans;

}

'use strict'
 let n = readline();
for( let i=0;i<n;i++)
{
    isok();
}
function isok()
{
    var a = readline().split(" ").map(Number);
    var id=a[1]/a[0];
    var les=(a[1]%a[0]);
    let ok  = a[0]-les;
    let ans = id*id*ok;
    id+=1;
    ans+= (id*id*les);
    print(ans);

}

'use strict'
 let n = readline;
for( let i=0;i<n;i++)
{
    isok();
}
function isok()
{
    var a = readLine().split(" ").map(Number);
    var id=a[1]/a[0];
    var les=(a[1]%a[0]);
    let ok  = a[0]-les;
    let ans = id*id*ok;
    id+=1;
    ans+= (id*id*les);
    print(ans);

}

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1)
        .forEach(line => {
            const [radiators, minSections] = line.split(' ').map(Number);
            const solution = new Array(radiators);
            solution.fill(0);
            let sections = 0;
            while(sections < minSections) {
                for (let i = 0; i < radiators && sections < minSections; i++) {
                    solution[i] += 1;
                    sections += 1;
                }
            }
            console.log(solution.map(v => v*v).reduce((sum, v) => sum + v, 0));
        });
});

process.stdin.setEncoding('utf-8').on('data', input => {
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [radiators, minSections] = line.split(' ').map(Number);
            const solution = new Array(radiators);
            solution.fill(minSections >= radiators ? Math.floor(radiators / minSections) : 0);
            let sections = 0;
            while(sections < minSections) {
                for (let i = 0; i < radiators && sections < minSections; i++) {
                    solution[i] += 1;
                    sections += 1;
                }
            }
            console.log(solution.map(v => v*v).reduce((sum, v) => sum + v, 0));
        });
});


/* TEST CASE
input
4 2 3 10
wwhw
output
2

input
5 2 4 1000
hhwhh
output
5

input
3 1 100 10
whw
output
0

input
5 2 4 13
hhwhh
output
4

Input
5 2 4 13
hhhwh
Output
3
Answer
4

*/
var n;
var swipeTime;
var rotateTime;
var needRotate;

function maxViewedPicture(totalTime) {
	var ret;
	var i;
	var viewCount = 0;
	var timeSpent = 0;
	var rev = n - 1, last;
	var t = 0;

	for (i = 0; i < n && timeSpent + t <= totalTime; i++) {
		timeSpent += t;
		t = 1;
		if (i > 0) {
			t += swipeTime;
		}

		if (needRotate[i]) {
			t += rotateTime;
		}

		if (timeSpent + t <= totalTime) {
			last = i;
			viewCount++;
		}
	}

	ret = viewCount;
	if (ret > 0 && ret < n) {
		for (var terminal = last + 1; terminal > 0; terminal--) {
			// decrement
			if (terminal <= last) {
				viewCount--;
				timeSpent -= 1 + swipeTime;
				if (needRotate[terminal]) {
					timeSpent -= rotateTime;
				}
			}
			// go reverse
			t = 1 + swipeTime;
			if (needRotate[rev]) {
				t += rotateTime;
			}
			//DEBUG:print("terminal - 1 =", terminal - 1, "n - rev = ", n - rev);
			while (timeSpent + swipeTime * Math.min(terminal - 1, n - rev) + t <= totalTime) {
				viewCount++;
				timeSpent += t;
				t = 1 + swipeTime;
				rev--;
				if (needRotate[rev]) {
					t += rotateTime;
				}
			}

			if (viewCount > ret) {
				ret = viewCount;
			}
		}
	}

	return ret;
}

function main() {
	var splitted = readline().split(' ');
	n = parseInt(splitted[0]);
	swipeTime = parseInt(splitted[1]);
	rotateTime = parseInt(splitted[2]);
	totalTime = parseInt(splitted[3]);
	splitted = readline();
	needRotate = new Array(n);
	for (var i = 0; i < n; i++) {
		needRotate[i] = (splitted[i] == 'w');
	}

	var answer = maxViewedPicture(totalTime);
	print(answer);
}

main();

var arr = readline().split(" ", 4).map(Number);
var n = arr[0], a = arr[1], b = arr[2], T = arr[3];
var str = readline();

function calc() {
    var maxPhotoCount = 1, left = [], right = [], i, tmp;
    left[0] = right[0] = 0;
    for (i = 1; i < n; ++i) {
        tmp = left[i - 1] + a + (str[i] === "w" ? b : 0) + 1;
        if (tmp + useTime > T) {
            break;
        }
        left[i] = tmp;
    }
    maxPhotoCount = Math.max(maxPhotoCount, left.length);
    if (maxPhotoCount === n) {
        return n;
    }
    for (i = 1; i < n; ++i) {
        tmp = right[i - 1] + a + (str[n - i] === "w" ? b : 0) + 1;
        if (tmp + useTime > T) {
            break;
        }
        right[i] = tmp;
    }
    maxPhotoCount = Math.max(maxPhotoCount, right.length);
    if (maxPhotoCount === n) {
        return n;
    }

    var time, beg, end, mid;
    end = right.length - 1;
    for (i  = 1; i < left.length; ++i) {
        time = T - useTime - left[i] - i * a;
        if (right[1] > time) {
            break;
        }
        beg = 1;
        while (true) {
            if (right[end] <= time) {
                break;
            }
            mid = Math.ceil((beg + end) / 2);
            if (right[mid] <= time) {
                beg = mid;
            } else {
                end = mid - 1;
            }
        }

        maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);
    }
    end = left.length - 1;
    for (i  = 1; i < right.length; ++i) {
        time = T - useTime - right[i] - i * a;
        if (left[1] > time) {
            break;
        }
        beg = 1;
        while (true) {
            if (left[end] <= time) {
                break;
            }
            mid = Math.ceil((beg + end) / 2);
            if (left[mid] <= time) {
                beg = mid;
            } else {
                end = mid - 1;
            }
        }
        maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);
    }
    return maxPhotoCount;
}

var useTime = 1 + (str[0] === "w" ? b : 0);
if (useTime > T) {
    print(0);
} else {
    print(calc());
}

var arr = readline().split(" ", 4).map(Number);
var n = arr[0], a = arr[1], b = arr[2], T = arr[3];
var str = readline();

var change = [];
for (var i = 0; i < n; ++i) {
    change[i] = Number(str[i] === "w");
}

function calc() {
    var maxPhotoCount = 1, left = [], right = [], i, tmp;
    left[0] = right[0] = 0;
    for (i = 1; i < n; ++i) {
        tmp = left[i - 1] + a + change[i] * b + 1;
        if (tmp + useTime > T) {
            break;
        }
        left[i] = tmp;
    }
    maxPhotoCount = Math.max(maxPhotoCount, left.length);
    if (maxPhotoCount === n) {
        return n;
    }
    for (i = 1; i < n; ++i) {
        tmp = right[i - 1] + a + change[n - i] * b + 1;
        if (tmp + useTime > T) {
            break;
        }
        right[i] = tmp;
    }
    maxPhotoCount = Math.max(maxPhotoCount, right.length);
    if (maxPhotoCount === n) {
        return n;
    }

    var time, beg, end, mid;
    end = right.length - 1;
    for (i  = 1; i < left.length; ++i) {
        time = T - useTime - left[i] - i * a;
        if (right[1] > time) {
            break;
        }
        beg = 1;
        while (true) {
            if (right[end] <= time) {
                break;
            }
            mid = Math.ceil((beg + end) / 2);
            if (right[mid] <= time) {
                beg = mid;
            } else {
                end = mid - 1;
            }
        }

        maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);
        if (maxPhotoCount === n) {
            return n;
        }
    }
    end = left.length - 1;
    for (i  = 1; i < right.length; ++i) {
        time = T - useTime - right[i] - i * a;
        if (left[1] > time) {
            break;
        }
        beg = 1;
        while (true) {
            if (left[end] <= time) {
                break;
            }
            mid = Math.ceil((beg + end) / 2);
            if (left[mid] <= time) {
                beg = mid;
            } else {
                end = mid - 1;
            }
        }
        maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);
        if (maxPhotoCount === n) {
            return n;
        }
    }
    return maxPhotoCount;
}

var useTime = change[0] * b + 1;
if (useTime > T) {
    print(0);
} else {
    print(calc());
}

/* TEST CASE
input
4 2 3 10
wwhw
output
2

input
5 2 4 1000
hhwhh
output
5

input
3 1 100 10
whw
output
0

input
5 2 4 13
hhwhh
output
4

*/
var n;
var swipeTime;
var rotateTime;
var needRotate;

function maxViewedPicture(totalTime) {
	var ret;
	var i;
	var viewCount = 0;
	var timeSpent = 0;
	var rev = n - 1, last;
	var t = 0;

	for (i = 0; i < n && timeSpent + t < totalTime; i++) {
		t = 1;
		if (i > 0) {
			t += swipeTime;
		}

		if (needRotate[i]) {
			t += rotateTime;
		}

		if (timeSpent + t <= totalTime) {
			timeSpent += t;
			last = i;
			viewCount++;
		}
	}

	ret = viewCount;
	if (ret > 0 && ret < n) {
		for (var terminal = last; terminal > 0; terminal--) {
			// decrement
			viewCount--;
			timeSpent -= 1 + swipeTime;
			if (needRotate[terminal]) {
				timeSpent -= rotateTime;
			}
			// long move to left
			var timeSwipeBack = (terminal - 1) * swipeTime;

			// go reverse
			t = 1 + swipeTime;
			if (needRotate[rev]) {
				t += rotateTime;
			}
			while (rev > terminal && timeSpent + timeSwipeBack + t <= totalTime) {
				viewCount++;
				timeSpent += t;
				rev--;
				t = 1 + swipeTime;
				if (needRotate[rev]) {
					t += rotateTime;
				}
			}

			if (viewCount > ret) {
				ret = viewCount;
			}
		}
	}

	return ret;
}

function main() {
	var splitted = readline().split(' ');
	n = parseInt(splitted[0]);
	swipeTime = parseInt(splitted[1]);
	rotateTime = parseInt(splitted[2]);
	totalTime = parseInt(splitted[3]);
	splitted = readline();
	needRotate = new Array(n);
	for (var i = 0; i < n; i++) {
		needRotate[i] = (splitted[i] == 'w');
	}

//	var answer = maxViewedPicture_BRUTEFORCE(0, 0, 0, totalTime);
	var answer = maxViewedPicture(totalTime);
	print(answer);
}

main();

/* TEST CASE
input
4 2 3 10
wwhw
output
2

input
5 2 4 1000
hhwhh
output
5

input
3 1 100 10
whw
output
0

input
5 2 4 13
hhwhh
output
4

*/
var n;
var swipeTime;
var rotateTime;
var needRotate;

function maxViewedPicture(totalTime) {
	var ret;
	var i;
	var viewCount = 0;
	var timeSpent = 0;
	var rev = n - 1, last;
	var t = 0;

	for (i = 0; i < n && timeSpent + t < totalTime; i++) {
		t = 1;
		if (i > 0) {
			t += swipeTime;
		}

		if (needRotate[i]) {
			t += rotateTime;
		}

		if (timeSpent + t <= totalTime) {
			timeSpent += t;
			last = i;
			viewCount++;
		}
	}

	ret = viewCount;
	if (ret > 0 && ret < n) {
		for (var terminal = last; terminal > 0; terminal--) {
			// decrement
			viewCount--;
			timeSpent -= 1 + swipeTime;
			if (needRotate[terminal]) {
				timeSpent -= rotateTime;
			}
			// long move to left
			var timeSwipeBack = (terminal - 1) * swipeTime;

			// go reverse
			t = 1 + swipeTime;
			if (needRotate[rev]) {
				t += rotateTime;
			}
			while (timeSpent + timeSwipeBack + t <= totalTime) {
				viewCount++;
				timeSpent += t;
				rev--;
				t = 1 + swipeTime;
				if (needRotate[rev]) {
					t += rotateTime;
				}
			}

			if (viewCount > ret) {
				ret = viewCount;
			}
		}
	}

	return ret;
}

function main() {
	var splitted = readline().split(' ');
	n = parseInt(splitted[0]);
	swipeTime = parseInt(splitted[1]);
	rotateTime = parseInt(splitted[2]);
	totalTime = parseInt(splitted[3]);
	splitted = readline();
	needRotate = new Array(n);
	for (var i = 0; i < n; i++) {
		needRotate[i] = (splitted[i] == 'w');
	}

//	var answer = maxViewedPicture_BRUTEFORCE(0, 0, 0, totalTime);
	var answer = maxViewedPicture(totalTime);
	print(answer);
}

main();

/* TEST CASE
input
4 2 3 10
wwhw
output
2

input
5 2 4 1000
hhwhh
output
5

input
3 1 100 10
whw
output
0

input
5 2 4 13
hhwhh
output
4

*/
var n;
var swipeTime;
var rotateTime;
var needRotate;

function maxViewedPicture(totalTime) {
	var ret;
	var i;
	var viewCount = 0;
	var timeSpent = 0;
	var rev = n - 1, last;
	var t = 0;

	for (i = 0; i < n && timeSpent + t <= totalTime; i++) {
		timeSpent += t;
		t = 1;
		if (i > 0) {
			t += swipeTime;
		}

		if (needRotate[i]) {
			t += rotateTime;
		}

		if (timeSpent + t <= totalTime) {
			last = i;
			viewCount++;
		}
	}

	ret = viewCount;
	if (ret > 0 && ret < n) {
		for (var terminal = last; terminal > 0; terminal--) {
			// decrement
			viewCount--;
			timeSpent -= 1 + swipeTime;
			if (needRotate[terminal]) {
				timeSpent -= rotateTime;
			}
			// long move to left
			var timeSwipeBack = (terminal - 1) * swipeTime;

			// go reverse
			t = 1 + swipeTime;
			if (needRotate[rev]) {
				t += rotateTime;
			}
			while (timeSpent + timeSwipeBack + t <= totalTime) {
				viewCount++;
				timeSpent += t;
				t = 1 + swipeTime;
				rev--;
				if (needRotate[rev]) {
					t += rotateTime;
				}
			}

			if (viewCount > ret) {
				ret = viewCount;
			}
		}
	}

	return ret;
}

function main() {
	var splitted = readline().split(' ');
	n = parseInt(splitted[0]);
	swipeTime = parseInt(splitted[1]);
	rotateTime = parseInt(splitted[2]);
	totalTime = parseInt(splitted[3]);
	splitted = readline();
	needRotate = new Array(n);
	for (var i = 0; i < n; i++) {
		needRotate[i] = (splitted[i] == 'w');
	}

	var answer = maxViewedPicture(totalTime);
	print(answer);
}

main();

/* TEST CASE
input
4 2 3 10
wwhw
output
2

input
5 2 4 1000
hhwhh
output
5

input
3 1 100 10
whw
output
0

input
5 2 4 13
hhwhh
output
4

*/
var n;
var swipeTime;
var rotateTime;
var orientations;

function maxViewedPicture_BRUTEFORCE(index1, index2, currentIndex, t) {
	if (index1 != index2 && ((n + index1) % n == index2 % n)) {
		return 0;
	}

	var ret = 0;
	var timeSpent = 1;
	if (orientations[(n + currentIndex) % n] == 'w') {
		timeSpent += rotateTime;
	}
	if (t - timeSpent >= 0) {
		ret = 1
			+ Math.max( maxViewedPicture_BRUTEFORCE(index1, index2 + 1, index2 + 1
										, t - timeSpent
											- swipeTime * (currentIndex == index2 ? 1 : (index2 - index1 + 1)))
					   ,maxViewedPicture_BRUTEFORCE(index1 - 1, index2, index1 - 1
										, t - timeSpent
											- swipeTime * (currentIndex == index1 ? 1 : (index2 - index1 + 1)))
					);
	}

	return ret;
}

function maxViewedPicture(totalTime) {
	var ret = 0;
	var viewCount;
	var i;
	var timeRemain;
	for (var terminal = n - 1; terminal >= 0 && ret < n; terminal--) {
		viewCount = 0;
		timeRemain = totalTime;

		for (i = 0; i <= terminal && timeRemain > 0; i++) {
			if (orientations[i] == 'w') {
				timeRemain -= rotateTime;
			}
			if (--timeRemain >= 0) {
				viewCount++;
			}
			timeRemain -= swipeTime;
		}

		timeRemain -= (terminal + 1) * swipeTime;
		for (i = n - 1; i > terminal + 1 && timeRemain > 0; i--) {
			if (orientations[i] == 'w') {
				timeRemain -= rotateTime;
			}
			if (--timeRemain >= 0) {
				viewCount++;
			}
			timeRemain -= swipeTime;
		}

		if (viewCount > ret) {
			ret = viewCount;
		}
	}

	return ret;
}

function main() {
	var splitted = readline().split(' ');
	n = parseInt(splitted[0]);
	swipeTime = parseInt(splitted[1]);
	rotateTime = parseInt(splitted[2]);
	totalTime = parseInt(splitted[3]);
	orientations = readline();

//	var answer = maxViewedPicture_BRUTEFORCE(0, 0, 0, totalTime);
	var answer = maxViewedPicture(totalTime);
	print(answer);
}

main();

var arr = readline().split(" ", 4).map(Number);
var n = arr[0], a = arr[1], b = arr[2], T = arr[3];
var str = readline();

var photoCount = 0, useTime = 0, maxPhotoCount;
if (str[0] === "w") {
    useTime += b;
}
++useTime;
if (useTime > T) {
    print(0);
} else {
    ++photoCount;
    maxPhotoCount = 1;

    for (var i = 1; i < n; ++i) {
        useTime += a + 1;
        if (str[i] === "w") {
            useTime += b;
        }
        if (useTime <= T) {
            ++photoCount;
        } else {
            break;
        }
        var photoOut = 0;
        if ((i + 1) * a + 1 <= T - useTime) {
            var timeOut = T - useTime - i * a;
            for (var j = n - 1; j > i; --j) {
                timeOut -= a + 1;
                if (str[j] === "w") {
                    timeOut -= b;
                }
                if (timeOut >= 0) {
                    ++photoOut;
                } else {
                    break;
                }
            }
        }
        maxPhotoCount = Math.max(maxPhotoCount, photoCount + photoOut);
        if (maxPhotoCount === n) {
            break;
        }
    }
    print(maxPhotoCount);
}

var arr = readline().split(" ", 4).map(Number);
var n = arr[0], a = arr[1], b = arr[2], T = arr[3];
var str = readline();

var change = [];
for (var i = 0; i < n; ++i) {
    change[i] = Number(str[i] === "w");
}

function calc() {
    var maxPhotoCount = 1, left = [], right = [], i, tmp;
    left[0] = right[0] = useTime;
    for (i = 1; i < n; ++i) {
        tmp = left[i - 1] + a + change[i] * b + 1;
        if (tmp > T) {
            break;
        }
        left[i] = tmp;
    }
    maxPhotoCount = Math.max(maxPhotoCount, left.length);
    if (maxPhotoCount === n) {
        return n;
    }
    for (i = 1; i < n; ++i) {
        tmp = right[i - 1] + a + change[n - i] * b + 1;
        if (tmp > T) {
            break;
        }
        right[i] = tmp;
    }
    maxPhotoCount = Math.max(maxPhotoCount, right.length);
    if (maxPhotoCount === n) {
        return n;
    }

    var time, beg, end, mid;
    end = right.length - 1;
    for (i  = 1; i < left.length; ++i) {
        time = T - left[i] - i * a;
        if (right[1] > time) {
            break;
        }
        beg = 1;
        while (true) {
            if (right[end] <= time) {
                break;
            }
            mid = Math.ceil((beg + end) / 2);
            if (right[mid] <= time) {
                beg = mid;
            } else {
                end = mid - 1;
            }
        }
        maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);
        if (maxPhotoCount === n) {
            return n;
        }
    }
    end = left.length - 1;
    for (i  = 1; i < right.length; ++i) {
        time = T - right[i] - i * a;
        if (left[1] > time) {
            break;
        }
        beg = 1;
        while (true) {
            if (left[end] <= time) {
                break;
            }
            mid = Math.ceil((beg + end) / 2);
            if (left[mid] <= time) {
                beg = mid;
            } else {
                end = mid - 1;
            }
        }
        maxPhotoCount = Math.max(maxPhotoCount, i + end + 1);
        if (maxPhotoCount === n) {
            return n;
        }
    }
    return maxPhotoCount;
}

var useTime = change[0] * b + 1;
if (useTime > T) {
    print(0);
} else {
    print(calc());
}


var n = Number(readline());

var data = readline().split(" ");

var map = {};
for(var i = 0; i < n; i++) {
    map[data[i]] = i;
}

var min = n;
var minNumber = null;
Object.keys(map).forEach(function(number) {
    if (map[number] < min) {
        min = map[number];
        minNumber = number;
    }
});
print(minNumber);

var n = parseInt(readline());

var a = readline().split(' ');
var b = [];
var was = [];
var active;

for (var i = 0; i < n; i++) {
  b.push(parseInt(a[i]));
}

for (var i = n-1; i >= 0; i--) {
  if (!was[b[i]]) {
    was[b[i]] = true;
    active = b[i];
  }
}

print(active);

readline() // ignore # of cafes
var shistory = readline().split(' ')
// var history = '1 3 2 1 2'.split(' ')
// var history = '2 1 2 2 4 1'.split(' ')

var cafes = {}
for (var i = 0; i < shistory.length; i++)
  cafes[shistory[i]] = i
var order = Object.getOwnPropertyNames(cafes).sort(function(a,b) { return cafes[a] - cafes[b] })
print(order[0])
// console.log(order[0])

main();

function main(){

    visits = new Array(200002);
    visits.fill(0);

    n = parseInt(readline());
    input = readline().split(' ');
    for(var i=0; i<input.length; i++) {
        input[i] = parseInt(input[i]);
        visits[input[i]]++;
    }

    for(var i=0; i<input.length; i++) {
        visits[input[i]]--;
        if(visits[input[i]]==0){
            print(input[i]);
            return;
        }
    }

}

main();

function main(){

    visits = new Array(20002);
    visits.fill(0);

    n = parseInt(readline());
    input = readline().split(' ');
    for(var i=0; i<input.length; i++) {
        input[i] = parseInt(input[i]);
    }

    ans = 0;
    for(var i=0; i<input.length; i++) {
        if(visits[input[i]]==1)
            break;
        else{
            ans = i+1;
            visits[input[i]]=1;
        }
    }
    print(ans);
}

main();

function main(){

    visits = new Array(20002);
    visits.fill(0);

    n = parseInt(readline());
    input = readline().split(' ');
    for(var i=0; i<input.length; i++) {
        input[i] = parseInt(input[i]);
        visits[input[i]]++;
    }

    for(var i=0; i<input.length; i++) {
        visits[input[i]]--;
        if(visits[input[i]]==0){
            print(input[i]);
            return;
        }
    }

}