Nura wants to buy k gadgets. She has only s burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing.

Nura can buy gadgets for n days. For each day you know the exchange rates of dollar and pound, so you know the cost of conversion burles to dollars or to pounds.

Each day (from 1 to n) Nura can buy some gadgets by current exchange rate. Each day she can buy any gadgets she wants, but each gadget can be bought no more than once during n days.

Help Nura to find the minimum day index when she will have k gadgets. Nura always pays with burles, which are converted according to the exchange rate of the purchase day. Nura can't buy dollars or pounds, she always stores only burles. Gadgets are numbered with integers from 1 to m in order of their appearing in input.


-----Input-----

First line contains four integers n, m, k, s (1 ≤ n ≤ 2·10^5, 1 ≤ k ≤ m ≤ 2·10^5, 1 ≤ s ≤ 10^9) — number of days, total number and required number of gadgets, number of burles Nura has.

Second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^6) — the cost of one dollar in burles on i-th day.

Third line contains n integers b_{i} (1 ≤ b_{i} ≤ 10^6) — the cost of one pound in burles on i-th day.

Each of the next m lines contains two integers t_{i}, c_{i} (1 ≤ t_{i} ≤ 2, 1 ≤ c_{i} ≤ 10^6) — type of the gadget and it's cost. For the gadgets of the first type cost is specified in dollars. For the gadgets of the second type cost is specified in pounds.


-----Output-----

If Nura can't buy k gadgets print the only line with the number -1.

Otherwise the first line should contain integer d — the minimum day index, when Nura will have k gadgets. On each of the next k lines print two integers q_{i}, d_{i} — the number of gadget and the day gadget should be bought. All values q_{i} should be different, but the values d_{i} can coincide (so Nura can buy several gadgets at one day). The days are numbered from 1 to n.

In case there are multiple possible solutions, print any of them.


-----Examples-----
Input
5 4 2 2
1 2 3 2 1
3 2 1 2 3
1 1
2 1
1 2
2 2

Output
3
1 1
2 3

Input
4 3 2 200
69 70 71 72
104 105 106 107
1 1
2 2
1 2

Output
-1

Input
4 3 1 1000000000
900000 910000 940000 990000
990000 999000 999900 999990
1 87654
2 76543
1 65432

Output
-1

Difficulty: HARD
Tags: Sorting

Amortized analysis

Greedy algorithms
Skill types: Sorting

Amortized analysis

Greedy algorithms

Starter code:

Solutions:
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=-10 ** 9, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, m, k, s) = map(int, input().split())
w = list(map(int, input().split()))
w1 = list(map(int, input().split()))
mi = [0] * n
mi1 = [0] * n
mi[0] = w[0]
mi1[0] = w1[0]
d = []
p = []
for i in range(m):
	(a, b) = map(int, input().split())
	if a == 1:
		d.append((b, i))
	else:
		p.append((b, i))
d.sort()
p.sort()
su = [0] * (len(d) + 1)
su1 = [0] * (len(p) + 1)
for i in range(len(d)):
	su[i + 1] = su[i] + d[i][0]
for i in range(len(p)):
	su1[i + 1] = su1[i] + p[i][0]
for i in range(1, n):
	mi[i] = min(mi[i - 1], w[i])
for i in range(1, n):
	mi1[i] = min(mi1[i - 1], w1[i])

def find(x):
	x -= 1
	dol = mi[x]
	pou = mi1[x]
	for i in range(min(k, len(d)) + 1):
		if k - i > len(p):
			continue
		ans = dol * su[i]
		ans += pou * su1[k - i]
		if ans <= s:
			return (True, i)
	return (False, -1)
st = 1
end = n
ans = (-1, -1)
while st <= end:
	mid = (st + end) // 2
	r = find(mid)
	if r[0] == True:
		ans = [mid, r[1]]
		end = mid - 1
	else:
		st = mid + 1
if ans[0] == -1:
	print(ans[0])
	sys.exit(0)
print(ans[0])
d1 = w.index(min(w[:ans[0]]))
p1 = w1.index(min(w1[:ans[0]]))
for i in range(ans[1]):
	print(d[i][1] + 1, d1 + 1)
for i in range(k - ans[1]):
	print(p[i][1] + 1, p1 + 1)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	(n, m, k, s) = mi()
	a = li()
	b = li()
	gadgets = [[] for i in range(2)]
	for i in range(m):
		(x, y) = mi()
		gadgets[x - 1].append([y, i + 1])
	gadgets[0].sort()
	gadgets[1].sort()
	sz = [len(gadgets[0]), len(gadgets[1])]

	def check(idx):
		mnx1 = inf
		mnx2 = inf
		for i in range(idx + 1):
			mnx1 = min(mnx1, a[i])
			mnx2 = min(mnx2, b[i])
		(l1, l2, res) = (0, 0, 0)
		if k > sz[0] + sz[1]:
			return 0
		for i in range(k):
			if l1 == sz[0]:
				res += gadgets[1][l2][0] * mnx2
				l2 += 1
			elif l2 == sz[1]:
				res += gadgets[0][l1][0] * mnx1
				l1 += 1
			elif gadgets[0][l1][0] * mnx1 <= gadgets[1][l2][0] * mnx2:
				res += gadgets[0][l1][0] * mnx1
				l1 += 1
			else:
				res += gadgets[1][l2][0] * mnx2
				l2 += 1
		return res <= s
	l = 0
	r = n - 1
	ans = -1
	while l <= r:
		mid = l + r >> 1
		if check(mid):
			ans = mid + 1
			r = mid - 1
		else:
			l = mid + 1
	print(ans)
	if ans == -1:
		return
	mnx1 = inf
	mnx2 = inf
	(idx1, idx2) = (-1, -1)
	for i in range(ans):
		if a[i] < mnx1:
			mnx1 = a[i]
			idx1 = i
		if b[i] < mnx2:
			mnx2 = b[i]
			idx2 = i
	(l1, l2, res) = (0, 0, [])
	for i in range(k):
		if l1 == sz[0]:
			res.append([gadgets[1][l2][1], idx2 + 1])
			l2 += 1
		elif l2 == sz[1]:
			res.append([gadgets[0][l1][1], idx1 + 1])
			l1 += 1
		elif gadgets[0][l1][0] * mnx1 <= gadgets[1][l2][0] * mnx2:
			res.append([gadgets[0][l1][1], idx1 + 1])
			l1 += 1
		else:
			res.append([gadgets[1][l2][1], idx2 + 1])
			l2 += 1
	for i in res:
		print(*i)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


from sys import stdin, stdout

def ints():
	return [int(x) for x in stdin.readline().split()]
(n, m, k, s) = ints()
a = ints()
b = ints()
d_gad = []
p_gad = []
for i in range(m):
	(t, c) = ints()
	if t == 1:
		d_gad.append([c, i + 1])
	else:
		p_gad.append([c, i + 1])
d_gad.sort()
p_gad.sort()
mn_dol = [0] * n
mn_pou = [0] * n
day_mn_dol = [1] * n
day_mn_pou = [1] * n
mn_dol[0] = a[0]
mn_pou[0] = b[0]
for i in range(1, n):
	mn_dol[i] = min(mn_dol[i - 1], a[i])
	day_mn_dol[i] = i + 1 if mn_dol[i] == a[i] else day_mn_dol[i - 1]
for i in range(1, n):
	mn_pou[i] = min(mn_pou[i - 1], b[i])
	day_mn_pou[i] = i + 1 if mn_pou[i] == b[i] else day_mn_pou[i - 1]

def Check(x):
	i = 0
	j = 0
	mnd = mn_dol[x]
	mnp = mn_pou[x]
	SuM = 0
	for u in range(k):
		if i == len(d_gad):
			SuM += p_gad[j][0] * mnp
			j += 1
		elif j == len(p_gad):
			SuM += d_gad[i][0] * mnd
			i += 1
		else:
			p1 = d_gad[i][0] * mnd
			p2 = p_gad[j][0] * mnp
			if p1 <= p2:
				SuM += p1
				i += 1
			else:
				SuM += p2
				j += 1
		if SuM > s:
			return False
	return True

def Print_Ans(x):
	i = 0
	j = 0
	mnd = mn_dol[x]
	mnp = mn_pou[x]
	dayd = day_mn_dol[x]
	dayp = day_mn_pou[x]
	ans = []
	for u in range(k):
		if i == len(d_gad):
			ans.append(str(p_gad[j][1]) + ' ' + str(dayp))
			j += 1
		elif j == len(p_gad):
			ans.append(str(d_gad[i][1]) + ' ' + str(dayd))
			i += 1
		elif d_gad[i][0] * mnd <= p_gad[j][0] * mnp:
			ans.append(str(d_gad[i][1]) + ' ' + str(dayd))
			i += 1
		else:
			ans.append(str(p_gad[j][1]) + ' ' + str(dayp))
			j += 1
	stdout.write('\n'.join(ans))
if not Check(n - 1):
	print(-1)
else:
	p = 0
	q = n - 1
	while p < q:
		mid = (p + q) // 2
		if Check(mid):
			q = mid
		else:
			p = mid + 1
	stdout.write(f'{p + 1}\n')
	Print_Ans(p)


from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def si():
	return str(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def lsi():
	return list(map(str, inp().split()))

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)
MOD = 10 ** 9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def inverseFactorials():
	n = len(INV_FACT)
	INV_FACT[n - 1] = inverse(FACT[n - 1])
	for i in range(n - 2, -1, -1):
		INV_FACT[i] = multiply(INV_FACT[i + 1], i + 1)

def coeffBinom(n, k):
	if n < k:
		return 0
	return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n - k]))

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path
(n, m, k, s) = li()
cd = li()
ce = li()
d = list()
e = list()
for i in range(m):
	(t, v) = li()
	if t == 1:
		d.append([v, i])
	else:
		e.append([v, i])
d.sort()
e.sort()
prd = [0 for i in range(len(d) + 1)]
pre = [0 for i in range(len(e) + 1)]
for i in range(max(len(d), len(e))):
	if i < len(d):
		prd[i + 1] = prd[i] + d[i][0]
	if i < len(e):
		pre[i + 1] = pre[i] + e[i][0]
md = list()
me = list()
mind = float('inf')
didx = -1
mine = float('inf')
eidx = -1
for i in range(n):
	if cd[i] < mind:
		mind = cd[i]
		didx = i
	if ce[i] < mine:
		mine = ce[i]
		eidx = i
	md.append([mind, didx])
	me.append([mine, eidx])
left = 0
right = n
compro = [-1, -1, -1, -1, -1]
flag = False
while left < right:
	mid = (left + right) // 2
	(currd, idxd) = md[mid]
	(curre, idxe) = me[mid]
	for i in range(k + 1):
		if i < len(prd) and k - i < len(pre):
			amount = currd * prd[i] + curre * pre[k - i]
			if amount <= s:
				flag = True
				compro = [mid + 1, idxd + 1, i, idxe + 1, k - i]
	if flag == True:
		right = mid
	else:
		left = mid + 1
	flag = False
if compro[0] != -1:
	print(compro[0])
	for i in range(compro[2]):
		print_list([d[i][1] + 1, compro[1]])
	for j in range(compro[4]):
		print_list([e[j][1] + 1, compro[3]])
else:
	print(-1)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'
import heapq

def can_do(check_days, n, m, k, s, d_gadgets, p_gadgets, prefx_min_d_val, prefx_min_p_val):
	min_d = prefx_min_d_val[check_days][0]
	min_p = prefx_min_p_val[check_days][0]
	min_d_idx = prefx_min_d_val[check_days][1]
	min_p_idx = prefx_min_p_val[check_days][1]
	vals_d = [0] * (k + 1)
	vals_p = [0] * (k + 1)
	for i in range(1, k + 1):
		if i <= len(d_gadgets):
			vals_d[i] = min_d * d_gadgets[i - 1][0] + vals_d[i - 1]
		if i <= len(p_gadgets):
			vals_p[i] = min_p * p_gadgets[i - 1][0] + vals_p[i - 1]
	for x in range(k + 1):
		if x <= len(d_gadgets) and k - x <= len(p_gadgets):
			if (x > 0 and vals_d[x] > 0 or x == 0) and (k - x > 0 and vals_p[k - x] > 0 or k - x == 0):
				total = vals_d[x] + vals_p[k - x]
				if total <= s:
					res = []
					for i in range(x):
						res.append((d_gadgets[i][1], min_d_idx))
					for i in range(k - x):
						res.append((p_gadgets[i][1], min_p_idx))
					return (True, res)
	return (False, [])

def check(n, m, k, s, d_gadgets, p_gadgets, prefx_min_d_val, prefx_min_p_val):
	lo = 0
	hi = n
	res = -1
	while lo <= hi:
		mid = lo + (hi - lo) // 2
		if can_do(mid, n, m, k, s, d_gadgets, p_gadgets, prefx_min_d_val, prefx_min_p_val)[0]:
			res = mid
			hi = mid - 1
		else:
			lo = mid + 1
	if res == -1:
		return (res, [])
	return (res, can_do(res, n, m, k, s, d_gadgets, p_gadgets, prefx_min_d_val, prefx_min_p_val)[1])

def solve():
	(n, m, k, s) = map(int, input().split())
	d_vals = list(map(int, input().split()))
	d_vals.insert(0, float('inf'))
	p_vals = list(map(int, input().split()))
	p_vals.insert(0, float('inf'))
	d_gadgets = []
	p_gadgets = []
	for i in range(m):
		(t, c) = map(int, input().split())
		if t == 1:
			d_gadgets.append((c, i + 1))
		else:
			p_gadgets.append((c, i + 1))
	prefx_min_d_val = [(d_vals[0], 0)] * len(d_vals)
	for i in range(1, len(d_vals)):
		if prefx_min_d_val[i - 1][0] < d_vals[i]:
			prefx_min_d_val[i] = (prefx_min_d_val[i - 1][0], prefx_min_d_val[i - 1][1])
		else:
			prefx_min_d_val[i] = (d_vals[i], i)
	prefx_min_p_val = [(p_vals[0], 0)] * len(p_vals)
	for i in range(1, len(p_vals)):
		if prefx_min_p_val[i - 1][0] < p_vals[i]:
			prefx_min_p_val[i] = (prefx_min_p_val[i - 1][0], prefx_min_p_val[i - 1][1])
		else:
			prefx_min_p_val[i] = (p_vals[i], i)
	d_gadgets.sort(key=lambda x: x[0])
	p_gadgets.sort(key=lambda x: x[0])
	(res, r) = check(n, m, k, s, d_gadgets, p_gadgets, prefx_min_d_val, prefx_min_p_val)
	cout << res << endl
	for p in r:
		cout << p[0] << ' ' << p[1] << endl

def main():
	solve()
main()


import sys
from itertools import accumulate
(n, m, k, s) = map(int, input().split())
_rate = [list(map(int, input().split())), list(map(int, input().split()))]
rate = [list(accumulate(_rate[0], min)), list(accumulate(_rate[1], min))]
items = [[[0, -1]], [[0, -1]]]
for i in range(m):
	(t, c) = map(int, sys.stdin.readline().split())
	items[t - 1].append([c, i + 1])
items[0].sort()
items[1].sort()
for i in range(2):
	for j in range(1, len(items[i])):
		items[i][j][0] += items[i][j - 1][0]
(ok, ng) = (n, -1)
ans_size = [0, 0]
while abs(ok - ng) > 1:
	mid = ok + ng >> 1
	cnt_1 = min(len(items[0]) - 1, k)
	cnt_2 = k - cnt_1
	while cnt_1 >= 0 and cnt_2 < len(items[1]):
		dollers = items[0][cnt_1][0]
		pounds = items[1][cnt_2][0]
		if dollers * rate[0][mid] + pounds * rate[1][mid] <= s:
			ok = mid
			ans_size = [cnt_1, cnt_2]
			break
		cnt_1 -= 1
		cnt_2 += 1
	else:
		ng = mid
if ok < n:
	print(ok + 1)
	for i in range(2):
		day = 0
		for j in range(0, n):
			if _rate[i][j] == rate[i][ok]:
				day = j + 1
				break
		for j in range(1, ans_size[i] + 1):
			print(items[i][j][1], day)
else:
	print(-1)


from itertools import accumulate
import sys

def solve(f, g):
	(n, m, k, s) = [int(x) for x in f.readline().split()]
	a_price = [(int(x), i + 1) for (i, x) in enumerate(f.readline().split())]
	b_price = [(int(x), i + 1) for (i, x) in enumerate(f.readline().split())]
	a_gadgets = []
	b_gadgets = []
	for (i, line) in enumerate(f):
		(t, price) = [int(x) for x in line.split()]
		if t == 1:
			a_gadgets.append((price, i + 1))
		else:
			b_gadgets.append((price, i + 1))
	a_gadgets.sort()
	b_gadgets.sort()
	prefix_a = [0] + list(accumulate((gadget[0] for gadget in a_gadgets)))
	prefix_b = [0] + list(accumulate((gadget[0] for gadget in b_gadgets)))
	la = min(k, len(a_gadgets))
	lb = min(k, len(b_gadgets))
	min_price_for_k = [(prefix_a[i], prefix_b[k - i], i) for i in range(k - lb, la + 1)]
	for i in range(1, n):
		a_price[i] = min(a_price[i], a_price[i - 1])
		b_price[i] = min(b_price[i], b_price[i - 1])

	def expence(day):
		return lambda x: a_price[day][0] * x[0] + b_price[day][0] * x[1]
	(x, y) = (0, n - 1)
	while x <= y - 1:
		day = (x + y) // 2
		min_cost = min(min_price_for_k, key=expence(day))
		if expence(day)(min_cost) > s:
			x = day + 1
		else:
			y = day
	min_cost = min(min_price_for_k, key=expence(x))
	if expence(x)(min_cost) > s:
		g.write('-1\n')
	else:
		g.write(str(x + 1) + '\n')
		i1 = min_cost[-1]
		(A, B) = (' ' + str(a_price[x][1]) + '\n', ' ' + str(b_price[x][1]) + '\n')
		for i in range(i1):
			g.write(str(a_gadgets[i][1]) + A)
		for i in range(k - i1):
			g.write(str(b_gadgets[i][1]) + B)
solve(sys.stdin, sys.stdout)