// http://www.spoj.com/problems/AMR10F/

var stdin = process.stdin;
var endOfLine = require('os').EOL;

var writeLn = function (msg) {
	process.stdout.write(msg + endOfLine);
};

var countCookies = function (nrPiles, shortestPile, heightDifference) {
	var sum = 0;
	var currentPile = shortestPile;

	for (var c = 0; c < nrPiles; c++) {
		sum += currentPile;
		currentPile += heightDifference;
	}

	return sum;
};

var input = '';
// resume stdin in the parent process (node app won't quit all by itself
// unless an error or process.exit() happens)
stdin.resume();

// i don't want binary, do you?
stdin.setEncoding( 'utf8' );

process.stdin.on('data', function(buf) { input += buf.toString(); });
// on data from stdin
stdin.on('end', function(){
	var lines = input.split(endOfLine);

	// Read how many test cases there are
	var nrTestCases = parseInt(lines[0]);

	// Read the test cases
	var offset = 1;
	for (var i = 0; i < nrTestCases; i++) {
		var line = lines[offset+i];
		var data = line.split(' ');
		var nrPins = parseInt(data[0]);
		var nrColours = parseInt(data[1]);
		var nrGuessed = parseInt(data[2]);

		writeLn('pins ' + nrPins);
		writeLn('colours ' + nrColours);
writeLn('guessed ' + nrGuessed);
// Väntad: 4 3 2, 4 6 2, 8 9 3
		// Read "guesses"
		var nrGuesses = nrGuessed * 2;
		for (var g = 0; g < nrGuesses; g+=2) {
			var colors = lines[offset+i+g+1].split(' ');
			var points = lines[offset+i+g+2].split(' ');

			writeLn('c ' + colors);
			writeLn('p ' + points);

			var pointsBlack = parseInt(points[0]);
			var pointsWhite = parseInt(points[1]);
		}
		offset += nrGuesses;

		// Solve the test case
		//var nrCookies = countCookies(nrPiles, shortestPile, heightDifference);
		//writeLn(nrCookies);
	}

	process.exit();
});

@@ -415,19 +415,273 @@
 var 
-input = '';
+lines = (function () %7B%0A%09var input = '';%0A%09var lines;%0A%09var line = 0;%0A%0A%09return %7B%0A%09%09addInput: function (buf) %7B%0A%09%09%09input += buf.toString();%0A%09%09%7D,%0A%09%09setup: function () %7B%0A%09%09%09lines = input.split(endOfLine);%0A%09%09%7D,%0A%09%09next: function () %7B%0A%09%09%09return lines%5Bline++%5D;%0A%09%09%7D%0A%09%7D;%0A%7D());%0A%0A
 %0A// 
@@ -904,50 +904,22 @@
 a', 
-function(buf) %7B input += buf.toString(); %7D
+lines.addInput
 );%0A/
@@ -972,42 +972,38 @@
 )%7B%0A%09
-var 
 lines
- = input.split(endOfLine)
+.setup();%0A%09var lineNr = 0
 ;%0A%0A%09
@@ -1073,19 +1073,23 @@
 nt(lines
-%5B0%5D
+.next()
 );%0A%0A%09// 
@@ -1112,25 +1112,8 @@
 ses%0A
-%09var offset = 1;%0A
 %09for
@@ -1171,18 +1171,15 @@
 ines
-%5Boffset+i%5D
+.next()
 ;%0A%09%09
@@ -1562,22 +1562,15 @@
 ines
-%5Boffset+i+g+1%5D
+.next()
 .spl
@@ -1603,22 +1603,15 @@
 ines
-%5Boffset+i+g+2%5D
+.next()
 .spl
@@ -1763,34 +1763,11 @@
 %5D);%0A
+
 %09%09%7D
-%0A%09%09offset += nrGuesses;
 %0A%0A%09%09

Refactor input and line handling.