// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline int read_int() {
		int ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

const ll MAXN = 250000 + 10;
const ll MAXM = 1e7 + 10;
int n, m, q;
vector<int> h1[MAXN];
vector<int> c1[MAXN];
int lft[MAXM], rgh[MAXM];
vll dp;
int hs[MAXM];
ll cost[MAXM];

void count_lft() {
	vector<int> st;
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < hs[i]) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	vector<int> st;
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < hs[i]) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	vector<int> st;
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + cost[i]);
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + cost[i]);
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.push_back(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		h1[i].resize(k);
		c1[i].resize(k);
		for (int j = 0; j < k; j++) {
			h1[i][j] = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			c1[i][j] = io.read_int();
		}
	}
	q = io.read_int();
	ll j = 1;
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (int d = 0; d < sz(h1[id]); d++) {
			hs[j] = h1[id][d];
			cost[j] = c1[id][d] * 1ll * mul;
			++j;
		}
	}
}


// (c) 2019, redotter
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline int read_int() {
		int ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

const ll MAXN = 250000;
const ll MAXM = 1e7 + 1;
int n, m, q;
vector<int> h1[MAXN];
vector<int> c1[MAXN];
int lft[MAXM], rgh[MAXM];
ll dp[MAXM];
int hs[MAXM];
ll cost[MAXM];

void count_lft() {
	vector<int> st;
	st.reserve(m);
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < hs[i]) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	vector<int> st;
	st.reserve(m);
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < hs[i]) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	for (ll i = 0; i <= m; i++) {
		dp[i] = inf;
	}
	dp[0] = 0;
	vector<int> st;
	st.reserve(m);
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + cost[i]);
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + cost[i]);
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.pb(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		h1[i].resize(k);
		c1[i].resize(k);
		for (int j = 0; j < k; j++) {
			h1[i][j] = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			c1[i][j] = io.read_int();
		}
	}
	q = io.read_int();
	int j = 1;
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (int d = 0; d < sz(h1[id]); d++) {
			hs[j] = h1[id][d];
			cost[j] = c1[id][d] * 1ll * mul;
			++j;
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline int read_int() {
		int ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

const ll MAXN = 250000 + 10;
const ll MAXM = 1e7 + 10;
int n, m, q;
vector<int> h1[MAXN];
vector<int> c1[MAXN];
int lft[MAXM], rgh[MAXM];
ll dp[MAXM];
int hs[MAXM];
ll cost[MAXM];

void count_lft() {
	vector<int> st;
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < hs[i]) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	vector<int> st;
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < hs[i]) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	for (ll i = 0; i <= m; i++) {
		dp[i] = inf;
	}
	dp[0] = 0;
	vector<int> st;
	st.reserve(m);
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + cost[i]);
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + cost[i]);
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.pb(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		h1[i].resize(k);
		c1[i].resize(k);
		for (int j = 0; j < k; j++) {
			h1[i][j] = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			c1[i][j] = io.read_int();
		}
	}
	q = io.read_int();
	ll j = 1;
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (int d = 0; d < sz(h1[id]); d++) {
			hs[j] = h1[id][d];
			cost[j] = c1[id][d] * 1ll * mul;
			++j;
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st;
	st.push(0);
	for (ll i = 1; i <= m; i++) {
		ll z = -1;
		while (!st.empty() && st.top() >= lft[i]) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
			z = st.top();
			st.pop();
		}
		if (!st.empty()) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
		}
		if (z != -1) {
			st.push(z);
		}
		st.push(i);
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st;
	st.push(0);
	for (ll i = 1; i <= m; i++) {
		mineq(dp[i], dp[i - 1] + a[i].sd);
		ll z = -1;
		while (!st.empty() && st.top() >= lft[i]) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
			z = st.top();
			st.pop();
		}
		if (!st.empty()) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
		}
		if (z != -1) {
			st.push(z);
		}
		st.push(i);
		//for (ll j = lft[i] - 1; j < i; j++) {
		//	mineq(dp[i], dp[j] + a[i].sd);
		//}
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline int read_int() {
		int ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

const ll MAXN = 250000 + 10;
const ll MAXM = 1e7 + 10;
int n, m, q;
vector<pair<int, int>> ks[MAXN];
pair<int, ll> a[MAXM];
vector<int> lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1, 0);
	vector<int> st;
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < a[i].ft) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	vector<int> st;
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	vector<int> st;
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + ll(a[i].sd));
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + ll(a[i].sd));
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.push_back(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		ks[i].resize(k);
		for (int j = 0; j < k; j++) {
			ks[i][j].ft = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			ks[i][j].sd = io.read_int();
		}
	}
	q = io.read_int();
	ll j = 1;
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (pair<int, ll> p : ks[id]) {
			a[j++] = { p.ft, p.sd * mul };
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
	vll rev(m + 1, inf);
	for (ll i = 0; i <= m; i++) {
		mineq(rev[rgh[i]], i);
	}
	rgh = rev;
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<pll> st0;
	stack<pll> st1;
	st0.push({ 0, 0 }), st1.push({ 0, 0 });
	for (ll i = 1; i <= m; i++) {
		mineq(dp[i], dp[lft[i] - 1] + a[i].sd);
		pll z;
		while (!st0.empty() && st0.top().sd >= lft[i]) {
			dp[i] = st0.top().ft + a[i].sd;
			z = st0.top();
			st0.pop();
		}
		st0.push(z);
	/*	for (ll j = lft[i] - 1; j < i; j++) {
			mineq(dp[i], dp[j] + a[i].sd);
		}
	*/	for (ll j = rgh[i]; j < i; j++) {
			mineq(dp[i], dp[j - 1] + a[j].sd);
		}
		if (i != m) {
			st0.push({ dp[i], i });
			st1.push({ dp[i] + a[i + 1].sd, i });
		}
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline int read_int() {
		int ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

const ll MAXN = 250000;
const ll MAXM = 1e7 + 1;
int n, m, q;
vector<int> h1[MAXN];
vector<int> c1[MAXN];
int lft[MAXM], rgh[MAXM];
ll dp[MAXM];
int hs[MAXM];
ll cost[MAXM];

void count_lft() {
	vector<int> st;
	st.reserve(m);
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < hs[i]) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	vector<int> st;
	st.reserve(m);
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < hs[i]) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	for (ll i = 0; i <= m; i++) {
		dp[i] = inf;
	}
	dp[0] = 0;
	vector<int> st;
	st.reserve(m);
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + cost[i]);
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + cost[i]);
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] >= dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.pb(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		h1[i].resize(k);
		c1[i].resize(k);
		for (int j = 0; j < k; j++) {
			h1[i][j] = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			c1[i][j] = io.read_int();
		}
	}
	q = io.read_int();
	int j = 1;
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (int d = 0; d < sz(h1[id]); d++) {
			hs[j] = h1[id][d];
			cost[j] = c1[id][d] * 1ll * mul;
			++j;
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline int read_int() {
		int ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

const ll MAXN = 250000 + 10;
const ll MAXM = 1e7 + 10;
int n, m, q;
vector<int> h1[MAXN];
vector<int> c1[MAXN];
int lft[MAXM], rgh[MAXM];
ll dp[MAXM];
int hs[MAXM];
ll cost[MAXM];

void count_lft() {
	vector<int> st;
	st.reserve(m);
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < hs[i]) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	vector<int> st;
	st.reserve(m);
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < hs[i]) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	for (ll i = 0; i <= m; i++) {
		dp[i] = inf;
	}
	dp[0] = 0;
	vector<int> st;
	st.reserve(m);
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + cost[i]);
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + cost[i]);
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.pb(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		h1[i].resize(k);
		c1[i].resize(k);
		for (int j = 0; j < k; j++) {
			h1[i][j] = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			c1[i][j] = io.read_int();
		}
	}
	q = io.read_int();
	int j = 1;
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (int d = 0; d < sz(h1[id]); d++) {
			hs[j] = h1[id][d];
			cost[j] = c1[id][d] * 1ll * mul;
			++j;
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st;
	st.push(0);
	for (ll i = 1; i <= m; i++) {
		mineq(dp[i], dp[i - 1] + a[i].sd);
		ll z = -1;
		while (!st.empty() && st.top() >= lft[i]) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
			z = st.top();
			st.pop();
		}
		if (z != -1) {
			st.push(z);
		}
		if (!st.empty()) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
		}
		st.push(i);
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline int read_int() {
		int ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

const ll MAXN = 250000 + 10;
const ll MAXM = 1e7 + 10;
int n, m, q;
vector<int> h1[MAXN];
vector<int> c1[MAXN];
vector<int> lft, rgh;
vll dp;
int hs[MAXM];
ll cost[MAXM];

void count_lft() {
	lft.resize(m + 1, 0);
	vector<int> st;
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < hs[i]) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	vector<int> st;
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < hs[i]) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	vector<int> st;
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + cost[i]);
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + cost[i]);
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.push_back(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		h1[i].resize(k);
		c1[i].resize(k);
		for (int j = 0; j < k; j++) {
			h1[i][j] = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			c1[i][j] = io.read_int();
		}
	}
	q = io.read_int();
	ll j = 1;
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (int d = 0; d < sz(h1[id]); d++) {
			hs[j] = h1[id][d];
			cost[j] = c1[id][d] * 1ll * mul;
			++j;
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	for (ll i = 1; i <= m; i++) {
		for (ll j = lft[i] - 1; j < i; j++) {
			mineq(dp[i], dp[j] + a[i].sd);
		}
		for (ll j = i - 1; j >= 1; j--) {
			if (rgh[j] < i) continue;
			mineq(dp[i], dp[j - 1] + a[j].sd);
		}
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline ll read_int() {
		ll ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

int n, m, q;
vector<vector<pair<int, int>>> ks;
vector<pair<int, ll>> a;
vector<int> lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1, 0);
	vector<int> st;
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < a[i].ft) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	vector<int> st;
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	vector<int> st;
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + ll(a[i].sd));
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + ll(a[i].sd));
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.push_back(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	ks.resize(n);
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		ks[i].resize(k);
		for (int j = 0; j < k; j++) {
			ks[i][j].ft = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			ks[i][j].sd = io.read_int();
		}
	}
	q = io.read_int();
	a.pb({ 0, 0 });
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (pair<int, ll> p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st;
	st.push(0);
	for (ll i = 1; i <= m; i++) {
	//	mineq(dp[i], dp[i - 1] + a[i].sd);
		ll z = -1;
		while (!st.empty() && st.top() >= lft[i]) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
			z = st.top();
			st.pop();
		}
		if (!st.empty()) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
		}
		if (z != -1) {
			st.push(z);
		}
		st.push(i);
		//for (ll j = lft[i] - 1; j < i; j++) {
		//	mineq(dp[i], dp[j] + a[i].sd);
		//}
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
	vll rev(m + 1, inf);
	for (ll i = 0; i <= m; i++) {
		mineq(rev[rgh[i]], i);
	}
	rgh = rev;
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st0;
	stack<ll, vll> st1;
	st0.push(0), st1.push(1);
	for (ll i = 1; i <= m; i++) {
		for (ll j = lft[i] - 1; j < i; j++) {
			mineq(dp[i], dp[j] + a[i].sd);
		}
		for (ll j = rgh[i]; j < i; j++) {
			mineq(dp[i], dp[j - 1] + a[j].sd);
		}
		if (i != m) {
			st0.push(dp[i]);
			st1.push(dp[i] + a[i + 1].sd);
		}
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st;
	st.push(0);
	for (ll i = 1; i <= m; i++) {
		ll z = -1;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
			z = st.top();
			st.pop();
		}
		if (z != -1) {
			st.push(z);
		}
		st.push(i);
		for (ll j = lft[i] - 1; j < i; j++) {
			mineq(dp[i], dp[j] + a[i].sd);
		}
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	vll st;
	st.pb(0);
	for (ll i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
		for (ll j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), j + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + a[i].sd);
		}
		for (ll j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.push_back(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st;
	st.push(0);
	for (ll i = 1; i <= m; i++) {
		mineq(dp[i], dp[i - 1] + a[i].sd);
		ll z = -1;
		while (!st.empty() && st.top() >= lft[i]) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
			z = st.top();
			st.pop();
		}
		if (!st.empty()) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
		}
		if (z != -1) {
			st.push(z);
		}
		st.push(i);
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline ll read_int() {
		ll ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	vll st;
	st.pb(0);
	for (ll i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
		for (ll j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), j + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + a[i].sd);
		}
		for (ll j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.push_back(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		k = io.read_int();
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			ks[i][j].ft = io.read_int();
		}
		for (ll j = 0; j < k; j++) {
			ks[i][j].sd = io.read_int();
		}
	}
	q = io.read_int();
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline ll read_int() {
		ll ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	vll st;
	st.pb(0);
	for (ll i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
		for (ll j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), j + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + a[i].sd);
		}
		for (ll j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.push_back(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		k = io.read_int();
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			ks[i][j].ft = io.read_int();
		}
		for (ll j = 0; j < k; j++) {
			ks[i][j].sd = io.read_int();
		}
	}
	q = io.read_int();
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max();
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

struct fast_io {
	inline char read_char() {
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		return c;
	}
	inline int read_int() {
		int ans = 0;
		char c = _getchar_nolock();
		while (c <= 32) {
			c = _getchar_nolock();
		}
		bool sign = 0;
		if (c == '-') {
			sign = 1;
			c = _getchar_nolock();
		}
		while ('0' <= c && c <= '9') {
			ans = (ans << 3) + (ans << 1) + (c - '0');
			c = _getchar_nolock();
		}
		if (sign) {
			ans = -ans;
		}
		return ans;
	}
	inline string read_string(bool full = 0) {
		string ans = "";
		char c = _getchar_nolock();
		while (c == 32) {
			c = _getchar_nolock();
		}
		while (full ? (c != '\n') : (c > 32)) {
			ans.pb(c);
			c = _getchar_nolock();
		}
		return ans;
	}
	inline void write_string(string s) {
		for (char c : s) {
			_putchar_nolock(c);
		}
	}
	inline void write_int(ll x) {
		write_string(to_string(x));
	}
	inline void write_char(char c) {
		_putchar_nolock(c);
	}
} io;

const ll MAXN = 250000 + 10;
const ll MAXM = 1e7 + 10;
int n, m, q;
vector<pair<int, int>> ks[MAXN];
vector<int> lft, rgh;
vll dp;
int hs[MAXM];
ll cost[MAXM];

void count_lft() {
	lft.resize(m + 1, 0);
	vector<int> st;
	for (int i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.back() < hs[i]) {
			mineq(lft[i], lft[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1, 0);
	vector<int> st;
	for (int i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.back() - i < hs[i]) {
			maxeq(rgh[i], rgh[st.back()]);
			st.popb();
		}
		st.pb(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	vector<int> st;
	st.pb(0);
	for (int i = 1; i <= m; i++) {
		mineq(dp[rgh[i]], dp[i - 1] + cost[i]);
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (st[j] + 1 < lft[i]) {
				st.resize(min(sz(st), ll(j) + 2));
				break;
			}
			mineq(dp[i], dp[st[j]] + cost[i]);
		}
		for (int j = sz(st) - 1; j >= 0; j--) {
			if (dp[st[j]] > dp[i]) {
				st.popb();
			} else {
				break;
			}
		}
		st.push_back(i);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	io.write_int(dp[m]);
}

void read() {
	n = io.read_int();
	m = io.read_int();
	for (int i = 0; i < n; i++) {
		int k;
		k = io.read_int();
		ks[i].resize(k);
		for (int j = 0; j < k; j++) {
			ks[i][j].ft = io.read_int();
		}
		for (int j = 0; j < k; j++) {
			ks[i][j].sd = io.read_int();
		}
	}
	q = io.read_int();
	ll j = 1;
	for (int i = 0; i < q; i++) {
		int id, mul;
		id = io.read_int();
		mul = io.read_int();
		--id;
		for (pair<int, ll> p : ks[id]) {
			hs[j] = p.ft;
			cost[j] = p.sd * 1ll * mul;
			++j;
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st;
	st.push(0);
	for (ll i = 1; i <= m; i++) {
	//	mineq(dp[i], dp[i - 1] + a[i].sd);
		ll z = -1;
		while (!st.empty() && st.top() + 1 >= lft[i]) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
			z = st.top();
			st.pop();
		}
		if (z != -1) {
			st.push(z);
		}
		st.push(i);
		//for (ll j = lft[i] - 1; j < i; j++) {
		//	mineq(dp[i], dp[j] + a[i].sd);
		//}
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	for (ll i = 1; i <= m; i++) {
		for (ll j = lft[i] - 1; j < i; j++) {
			mineq(dp[i], dp[j] + a[i].sd);
		}
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


// (c) 2019, redotter
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)((a).size())
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set
#define ft first
#define sd second
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\n"
#define y0 y0998244353
#define y1 y1998244353
#define die(cond) if (cond) for (;;) {}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef map<ll, ll> mll;
const ll inf = numeric_limits<ll>::max() / 2;
const ld eps = 1e-9;
const ld pi = acosl(-1);
template<typename T> inline bool mineq(T& a, T b) { return (a > b) ? (a = b, 1) : 0; }
template<typename T> inline bool maxeq(T& a, T b) { return (a < b) ? (a = b, 1) : 0; }

void solve(), read();

signed main() {
	fast;
	read();
	solve();
	return 0;
}

ll n, m, q;
vector<vector<pll>> ks;
vector<pll> a;
vll lft, rgh;
vll dp;

void count_lft() {
	lft.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = 1; i <= m; i++) {
		lft[i] = i;
		while (!st.empty() && i - st.top() < a[i].ft) {
			mineq(lft[i], lft[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_rgh() {
	rgh.resize(m + 1);
	stack<ll, vll> st;
	for (ll i = m; i >= 1; i--) {
		rgh[i] = i;
		while (!st.empty() && st.top() - i < a[i].ft) {
			maxeq(rgh[i], rgh[st.top()]);
			st.pop();
		}
		st.push(i);
	}
}
void count_dp() {
	dp.resize(m + 1, inf);
	dp[0] = 0;
	stack<ll, vll> st;
	st.push(0);
	for (ll i = 1; i <= m; i++) {
		ll z = -1;
		while (!st.empty() && st.top() >= lft[i]) {
			mineq(dp[i], dp[st.top()] + a[i].sd);
			z = st.top();
			st.pop();
		}
		if (z != -1) {
			st.push(z);
		}
		st.push(i);
		//for (ll j = lft[i] - 1; j < i; j++) {
		//	mineq(dp[i], dp[j] + a[i].sd);
		//}
		mineq(dp[rgh[i]], dp[i - 1] + a[i].sd);
	}
}

void solve() {
	count_lft();
	count_rgh();
	count_dp();
	cout << dp[m] << endl;
}

void read() {
	cin >> n >> m;
	ks.resize(n);
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		ks[i].resize(k);
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].ft;
		}
		for (ll j = 0; j < k; j++) {
			cin >> ks[i][j].sd;
		}
	}
	cin >> q;
	a.pb({ 0, 0 });
	for (ll i = 0; i < q; i++) {
		ll id, mul;
		cin >> id >> mul;
		--id;
		for (pll p : ks[id]) {
			a.pb({ p.ft, p.sd * mul });
		}
	}
}


#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

#define N 10000007

int n,m,len,cnt,q,top,h[N],l[N],r[N],sta[N],size[N];
long long c[N],f[N];
vector<int> ht[N],ct[N];

long long min(int x,int y) { return x < y ? x : y ; }

int main()
{
	memset(l,0x3f,sizeof l);
	scanf("%d%d",&n,&m),cnt = top =  0;
	for (int i = 1;i <= n;++ i)
	{
		scanf("%d",&size[i]);
		ht[i].resize(size[i] + 1),ct[i].resize(size[i] + 1);
		for (int j = 1;j <= size[i];++ j) scanf("%d",&ht[i][j]);
		for (int j = 1;j <= size[i];++ j) scanf("%d",&ct[i][j]);
	}
	scanf("%d",&q);
	for (int i = 1,x,y;i<= q;++ i)
	{
		scanf("%d%d",&x,&y);
		for (int j = 1;j <= size[x];++ j) h[++ cnt] = ht[x][j],c[cnt] = (long long)ct[x][j] * (long long)y;
	}
	for (int i = 1;i <= m;++ i)
	{
		while (top && sta[top] + h[sta[top]] <= i) r[sta[top]] = i - 1,-- top;
		sta[++ top] = i;
	}
	while (top) r[sta[top]] = m,-- top;
	for (int i = m; i ;-- i)
	{
		while (top && sta[top] - h[sta[top]] >= i) l[sta[top]] = i + 1,-- top;
		sta[++ top] = i;
	}
	while (top) l[sta[top]] = 1,-- top;
	f[0] = 0ll,c[0] = 0x3f3f3f3f3f3f3f3f;
	for (int i = 1;i <= m;++ i)
	{
		f[i] = f[l[i] - 1] + c[i];
		while (top && r[sta[top]] < i) -- top;
		f[i] = min(f[i],f[sta[top] - 1] + c[sta[top]]);
		if(!top || f[i - 1] + c[i] < f[sta[top] - 1] + c[sta[top]]) sta[++ top] = i;
	}
	printf("%lld\n",f[m]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

#define N 10000007

int n,m,len,cnt,q,top,h[N],l[N],r[N],sta[N],siz[N];
long long c[N],f[N];
vector<int> ht[N],ct[N];

long long min(int x,int y) { return x < y ? x : y ; }

int main()
{
	memset(l,0x3f,sizeof l);
	scanf("%d%d",&n,&m),cnt = top =  0;
	for (int i = 1;i <= n;++ i)
	{
		scanf("%d",&siz[i]);
		ht[i].resize(siz[i] + 1),ct[i].resize(siz[i] + 1);
		for (int j = 1;j <= siz[i];++ j) scanf("%d",&ht[i][j]);
		for (int j = 1;j <= siz[i];++ j) scanf("%d",&ct[i][j]);
	}
	scanf("%d",&q);
	for (int i = 1,x,y;i<= q;++ i)
	{
		scanf("%d%d",&x,&y);
		for (int j = 1;j <= siz[x];++ j) h[++ cnt] = ht[x][j],c[cnt] = (long long)ct[x][j] * (long long)y;
	}
	for (int i = 1;i <= m;++ i)
	{
		while (top && sta[top] + h[sta[top]] <= i) r[sta[top]] = i - 1,-- top;
		sta[++ top] = i;
	}
	while (top) r[sta[top]] = m,-- top;
	for (int i = m; i ;-- i)
	{
		while (top && sta[top] - h[sta[top]] >= i) l[sta[top]] = i + 1,-- top;
		sta[++ top] = i;
	}
	while (top) l[sta[top]] = 1,-- top;
	f[0] = 0ll,c[0] = 0x3f3f3f3f3f3f3f3f;
	for (int i = 1;i <= m;++ i)
	{
		f[i] = f[l[i] - 1] + c[i];
		while (top && r[sta[top]] < i) -- top;
		f[i] = min(f[i],f[sta[top] - 1] + c[sta[top]]);
		if(!top || f[i - 1] + c[i] < f[sta[top] - 1] + c[sta[top]]) sta[++ top] = i;
	}
	printf("%lld\n",f[m]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

#define N 10000007

int n,m,len,cnt,q,top,h[N],l[N],r[N],sta[N],siz[N];
long long c[N],f[N];
vector<int> ht[N],ct[N];

long long min(long long x,long long y) { return x < y ? x : y ; }

int main()
{
	memset(l,0x3f,sizeof l);
	scanf("%d%d",&n,&m),cnt = top =  0;
	for (int i = 1;i <= n;++ i)
	{
		scanf("%d",&siz[i]);
		ht[i].resize(siz[i] + 1),ct[i].resize(siz[i] + 1);
		for (int j = 1;j <= siz[i];++ j) scanf("%d",&ht[i][j]);
		for (int j = 1;j <= siz[i];++ j) scanf("%d",&ct[i][j]);
	}
	scanf("%d",&q);
	for (int i = 1,x,y;i<= q;++ i)
	{
		scanf("%d%d",&x,&y);
		for (int j = 1;j <= siz[x];++ j) h[++ cnt] = ht[x][j],c[cnt] = (long long)ct[x][j] * (long long)y;
	}
	for (int i = 1;i <= m;++ i)
	{
		while (top && sta[top] + h[sta[top]] <= i) r[sta[top]] = i - 1,-- top;
		sta[++ top] = i;
	}
	while (top) r[sta[top]] = m,-- top;
	for (int i = m; i ;-- i)
	{
		while (top && sta[top] - h[sta[top]] >= i) l[sta[top]] = i + 1,-- top;
		sta[++ top] = i;
	}
	while (top) l[sta[top]] = 1,-- top;
	f[0] = 0ll,c[0] = 0x3f3f3f3f3f3f3f3f;
	for (int i = 1;i <= m;++ i)
	{
		f[i] = f[l[i] - 1] + c[i];
		while (top && r[sta[top]] < i) -- top;
		f[i] = min(f[i],f[sta[top] - 1] + c[sta[top]]);
		if(!top || f[i - 1] + c[i] < f[sta[top] - 1] + c[sta[top]]) sta[++ top] = i;
	}
	printf("%lld\n",f[m]);
	return 0;
}


#pragma comment(linker, "/stack:32000000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>
#include <string.h>
#include <ctime>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

ll maxcost = (ll)2e18;
vector<ll> fen;

ll getmin(int r)
{
	ll result = maxcost;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result = min (result, fen[r]);
	return result;
}

void update (int i, ll new_val)
{
	for (; i < sz(fen); i = (i | (i+1)))
		fen[i] = min (fen[i], new_val);
}

vector<int> fenmax;
int getmax(int r)
{
	int result = -1;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result = max (result, fenmax[r]);
	return result;
}

void update_max (int i, int new_val)
{
	for (; i < sz(fenmax); i = (i | (i+1)))
		fenmax[i] = max(fenmax[i], new_val);
}

vector<int> get_righttarget(const vector<int>& a) {
  vector<int> res(sz(a));
  fenmax = vector<int>(sz(a), -1);
  for (int i = sz(a) - 1; i >= 0; --i) {
    int target_ind = min(sz(a) - 1, i + a[i] - 1);
    int cur_res = target_ind;
    int cascade_res = getmax(target_ind);
    cur_res = max(cur_res, cascade_res);
    res[i] = cur_res;
    update_max(i, cur_res);
  }
  return res;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
  int N, m; scanf("%d%d", &N, &m);
  vector<vector<int> > ka(N);
  vector<vector<ll> > kcost(N);
  for (int i = 0; i < N; ++i) {
    int ki; scanf("%d", &ki);
    for (int j = 0; j < ki; ++j) {
      int cura; scanf("%d", &cura);
      ka[i].push_back(cura);
    }

    for (int j = 0; j < ki; ++j) {
      int curcost; scanf("%d", &curcost);
      kcost[i].push_back(curcost);
    }
  }

  vector<int> a(m);
  vector<ll> cost(m);

  int q; scanf("%d", &q);
  int beg = 0;
  for (int iter = 0; iter < q; ++iter) {
    int curid, curmult; scanf("%d%d", &curid, &curmult); --curid;
    for (int j = 0; j < sz(ka[curid]); ++j) {
      a[beg + j] = ka[curid][j];
      ll cur_cost = kcost[curid][j] * curmult;
      cost[beg + j] = cur_cost;
    }
    beg += sz(ka[curid]);
  }

  vector<int> rtarget = get_righttarget(a);

  vector<int> reva = a;
  reverse(ALL(reva));
  vector<int> ltarget = get_righttarget(reva);
  reverse(ALL(ltarget));
  for (int i = 0; i < sz(ltarget); ++i) ltarget[i] = m-1-ltarget[i];

  vector<pii> rev_domino;
  for (int i = 0; i < m; ++i) {
    int to = ltarget[i];//i - a[i] + 1;
    to = max(to, 0);
    rev_domino.pb(mp(to, i));
  }
  sort(ALL(rev_domino));

  fen = vector<ll>(m + 1, maxcost);
  vector<ll> res(m + 1, maxcost);
  update(m, 0);
  res[m] = 0;

  int pos = sz(rev_domino) - 1;
  for (int i = m - 1; i >= 0; --i) {
    ll best_res = maxcost;
    while (pos >= 0 && rev_domino[pos].X == i) {
      int target_ind = rev_domino[pos].Y;
      ll target_cost = cost[target_ind];
      ll dp_cost = res[target_ind + 1];//getmin(target_ind + 1);
      ll cur_cost = dp_cost + target_cost;
      if (cur_cost < best_res) best_res = cur_cost;
      --pos;
    }

    int tind = rtarget[i];//min(i + a[i] - 1, m - 1);
    ll tcost = cost[i];
    ll dcost = getmin(tind + 1);
    ll ccost = dcost + tcost;
    if (ccost < best_res) best_res = ccost;

    res[i] = best_res;
    update(i, best_res);
  }

  ll result = res[0];
  cout << result << "\n";
	return 0;
}


#pragma comment(linker, "/stack:32000000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>
#include <string.h>
#include <ctime>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

ll maxcost = (ll)2e18;
vector<ll> fen;

ll getmin(int r)
{
	ll result = maxcost;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result = min (result, fen[r]);
	return result;
}

void update (int i, ll new_val)
{
	for (; i < sz(fen); i = (i | (i+1)))
		fen[i] = min (fen[i], new_val);
}

vector<int> fenmax;
int getmax(int r)
{
	int result = -1;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result = max (result, fenmax[r]);
	return result;
}

void update_max (int i, int new_val)
{
	for (; i < sz(fenmax); i = (i | (i+1)))
		fenmax[i] = max(fenmax[i], new_val);
}

vector<int> get_righttarget(const vector<int>& a) {
  vector<int> res(sz(a));
  fenmax = vector<int>(sz(a), -1);
  for (int i = sz(a) - 1; i >= 0; --i) {
    int target_ind = min(sz(a) - 1, i + a[i] - 1);
    int cur_res = target_ind;
    int cascade_res = getmax(target_ind);
    cur_res = max(cur_res, cascade_res);
    res[i] = cur_res;
    update_max(i, cur_res);
  }
  return res;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
  int N, m; scanf("%d%d", &N, &m);
  vector<vector<int> > ka(N);
  vector<vector<ll> > kcost(N);
  for (int i = 0; i < N; ++i) {
    int ki; scanf("%d", &ki);
    for (int j = 0; j < ki; ++j) {
      int cura; scanf("%d", &cura);
      ka[i].push_back(cura);
    }

    for (int j = 0; j < ki; ++j) {
      int curcost; scanf("%d", &curcost);
      kcost[i].push_back(curcost);
    }
  }

  vector<int> a(m);
  vector<ll> cost(m);

  int q; scanf("%d", &q);
  int beg = 0;
  for (int iter = 0; iter < q; ++iter) {
    int curid, curmult; scanf("%d%d", &curid, &curmult); --curid;
    for (int j = 0; j < sz(ka[curid]); ++j) {
      a[beg + j] = ka[curid][j];
      ll cur_cost = kcost[curid][j] * curmult;
      cost[beg + j] = cur_cost;
    }
    beg += sz(ka[curid]);
  }

  vector<int> rtarget = get_righttarget(a);

  vector<int> reva = a;
  reverse(ALL(reva));
  vector<int> ltarget = get_righttarget(reva);
  reverse(ALL(ltarget));
  for (int i = 0; i < sz(ltarget); ++i) ltarget[i] = m-1-ltarget[i];

  vector<pii> rev_domino;
  for (int i = 0; i < m; ++i) {
    int to = ltarget[i];//i - a[i] + 1;
    to = max(to, 0);
    rev_domino.pb(mp(to, i));
  }
  sort(ALL(rev_domino));

  fen = vector<ll>(m + 1, maxcost);
  vector<ll> res(m + 1, maxcost);
  update(m, 0);
  res[m] = 0;

  int pos = sz(rev_domino) - 1;
  for (int i = m - 1; i >= 0; --i) {
    ll best_res = maxcost;
    while (pos >= 0 && rev_domino[pos].X == i) {
      int target_ind = rev_domino[pos].Y;
      ll target_cost = cost[target_ind];
      ll dp_cost = getmin(target_ind + 1);
      ll cur_cost = dp_cost + target_cost;
      if (cur_cost < best_res) best_res = cur_cost;
      --pos;
    }

    int tind = rtarget[i];//min(i + a[i] - 1, m - 1);
    ll tcost = cost[i];
    ll dcost = getmin(tind + 1);
    ll ccost = dcost + tcost;
    if (ccost < best_res) best_res = ccost;

    res[i] = best_res;
    update(i, best_res);
  }

  ll result = res[0];
  cout << result << "\n";
	return 0;
}


#pragma comment(linker, "/stack:32000000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>
#include <string.h>
#include <ctime>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

ll maxcost = (ll)2e18;
vector<ll> fen;

ll getmin(int r)
{
	ll result = maxcost;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result = min (result, fen[r]);
	return result;
}

void update (int i, ll new_val)
{
	for (; i < sz(fen); i = (i | (i+1)))
		fen[i] = min (fen[i], new_val);
}

vector<int> fenmax;
int getmax(int r)
{
	int result = -1;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result = max (result, fenmax[r]);
	return result;
}

void update_max (int i, int new_val)
{
	for (; i < sz(fenmax); i = (i | (i+1)))
		fenmax[i] = max(fenmax[i], new_val);
}

vector<int> get_righttarget_slow(const vector<int>& a) {
  vector<int> res(sz(a));
  fenmax = vector<int>(sz(a), -1);
  for (int i = sz(a) - 1; i >= 0; --i) {
    int target_ind = min(sz(a) - 1, i + a[i] - 1);
    int cur_res = target_ind;
    int cascade_res = getmax(target_ind);
    cur_res = max(cur_res, cascade_res);
    res[i] = cur_res;
    update_max(i, cur_res);
  }
  return res;
}

vector<int> get_righttarget(const vector<int>& a) {
  vector<int> res(sz(a));
  for (int i = sz(a) - 1; i >= 0; --i) {
    int target_ind = min(sz(a) - 1, i + a[i] - 1);
    int j = i + 1;
    int tres = target_ind;
    while (j <= target_ind) {
      int mres = res[j];
      tres = max(tres, mres);
      j = res[j] + 1;
    }
    res[i] = tres;
  }
  return res;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
  int N, m; scanf("%d%d", &N, &m);
  vector<vector<int> > ka(N);
  vector<vector<ll> > kcost(N);
  for (int i = 0; i < N; ++i) {
    int ki; scanf("%d", &ki);
    for (int j = 0; j < ki; ++j) {
      int cura; scanf("%d", &cura);
      ka[i].push_back(cura);
    }

    for (int j = 0; j < ki; ++j) {
      int curcost; scanf("%d", &curcost);
      kcost[i].push_back(curcost);
    }
  }

  vector<int> a(m);
  vector<ll> cost(m);

  int q; scanf("%d", &q);
  int beg = 0;
  for (int iter = 0; iter < q; ++iter) {
    int curid, curmult; scanf("%d%d", &curid, &curmult); --curid;
    for (int j = 0; j < sz(ka[curid]); ++j) {
      a[beg + j] = ka[curid][j];
      ll cur_cost = kcost[curid][j] * curmult;
      cost[beg + j] = cur_cost;
    }
    beg += sz(ka[curid]);
  }

  vector<int> rtarget = get_righttarget(a);

  vector<int> reva = a;
  reverse(ALL(reva));
  vector<int> ltarget = get_righttarget(reva);
  reverse(ALL(ltarget));
  for (int i = 0; i < sz(ltarget); ++i) ltarget[i] = m-1-ltarget[i];

  vector<pii> rev_domino;
  for (int i = 0; i < m; ++i) {
    int to = ltarget[i];//i - a[i] + 1;
    to = max(to, 0);
    rev_domino.pb(mp(to, i));
  }
  sort(ALL(rev_domino));

  fen = vector<ll>(m + 1, maxcost);
  vector<ll> res(m + 1, maxcost);
  update(m, 0);
  res[m] = 0;

  int pos = sz(rev_domino) - 1;
  for (int i = m - 1; i >= 0; --i) {
    ll best_res = maxcost;
    while (pos >= 0 && rev_domino[pos].X == i) {
      int target_ind = rev_domino[pos].Y;
      ll target_cost = cost[target_ind];
      ll dp_cost = res[target_ind + 1];//getmin(target_ind + 1);
      ll cur_cost = dp_cost + target_cost;
      if (cur_cost < best_res) best_res = cur_cost;
      --pos;
    }

    int tind = rtarget[i];//min(i + a[i] - 1, m - 1);
    ll tcost = cost[i];
    ll dcost = getmin(tind + 1);
    ll ccost = dcost + tcost;
    if (ccost < best_res) best_res = ccost;

    res[i] = best_res;
    update(i, best_res);
  }

  ll result = res[0];
  cout << result << "\n";
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define N 10000010
#define K 300000
#define ll long long
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
ll n,m,i,j,k[K],q,id,mul,lp[N],rp[N],f[N],x,num,data[N],top,p,mn;
vector<ll> a[K],c[K];
struct node{
	ll height,cost;
}g[N];
int search(ll p){
	ll mid,k=0,l=1,r=top;
	while (l<=r){
		mid=(l+r)/2;
		if (data[mid]>=p){
			k=data[mid];
			r=mid-1;
		}
		else
			l=mid+1;
	}
	return k;
}
int main(){
	//freopen("shark.in","r",stdin);
	//freopen("shark.out","w",stdout);
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=n;i++){
		scanf("%lld",&k[i]);
		a[i].push_back(0);
		c[i].push_back(0);
		for (j=1;j<=k[i];j++){
			scanf("%lld",&x);
			a[i].push_back(x);
		}
		for (j=1;j<=k[i];j++){
			scanf("%lld",&x);
			c[i].push_back(x);
		}
	}
	scanf("%lld",&q);
	while (q--){
		scanf("%lld%lld",&id,&mul);
		for (i=num+1;i<=num+k[id];i++)
			g[i].height=a[id][i-num];
		for (i=num+1;i<=num+k[id];i++)
			g[i].cost=c[id][i-num]*mul;
		num+=k[id];
	}
	for (i=1;i<=num;i++)
		lp[i]=rp[i]=i;
	top=1;
	data[1]=1;
	for (i=2;i<=num;i++){
		while (top&&g[i].height>i-data[top])
			lp[i]=lp[data[top]],top--;
		data[++top]=i;
	}
	top=1;
	data[1]=num;
	for (i=num-1;i>=1;i--){
		while (top&&g[i].height>data[top]-i)
			rp[i]=rp[data[top]],top--;
		data[++top]=i;
	}
	top=1;
	data[1]=1;
	for (i=0;i<=num;i++)
		f[i]=1e18;
	f[1]=g[1].cost;
	f[rp[1]]=g[1].cost;
	f[rp[2]]=min(f[rp[2]],g[1].cost+g[2].cost);
	mn=1e18;
	mn=0;
	for (i=2;i<=num;i++){
		if (lp[i]==lp[i-1]&&mn){
			p=mn;
			if (f[i-1]<f[p])
				p=i-1,mn=i-1;
		}
		else{
			if (lp[i]>lp[i-1])
				p=0,mn=0;
			else{
				p=search(lp[i]-1);
				mn=p;
			}
		}
		if (p)
			f[i]=min(f[i],g[i].cost+f[p]);
		f[i]=min(f[i],g[i].cost+f[i-1]);
		if (lp[i]<=1)
			f[i]=min(f[i],g[i].cost);
		while (top&&f[i]<=f[data[top]])
			top--;
		data[++top]=i;
		f[rp[i+1]]=min(f[rp[i+1]],f[i]+g[i+1].cost);
	}
	printf("%lld\n",f[num]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define N 10000010
#define K 300000
#define ll long long
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
ll n,m,i,j,k[K],q,id,mul,lp[N],rp[N],f[N],x,num,data[N],top,p;
vector<ll> a[K],c[K];
struct node{
	ll height,cost;
}g[N];
int search(ll p){
	ll mid,k=0,l=1,r=top;
	while (l<=r){
		mid=(l+r)/2;
		if (data[mid]>=p){
			k=data[mid];
			r=mid-1;
		}
		else
			l=mid+1;
	}
	return k;
}
int main(){
	//freopen("shark.in","r",stdin);
	//freopen("shark.out","w",stdout);
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=n;i++){
		scanf("%lld",&k[i]);
		a[i].push_back(0);
		c[i].push_back(0);
		for (j=1;j<=k[i];j++){
			scanf("%lld",&x);
			a[i].push_back(x);
		}
		for (j=1;j<=k[i];j++){
			scanf("%lld",&x);
			c[i].push_back(x);
		}
	}
	scanf("%lld",&q);
	while (q--){
		scanf("%lld%lld",&id,&mul);
		for (i=num+1;i<=num+k[id];i++)
			g[i].height=a[id][i-num];
		for (i=num+1;i<=num+k[id];i++)
			g[i].cost=c[id][i-num]*mul;
		num+=k[id];
	}
	for (i=1;i<=num;i++)
		lp[i]=rp[i]=i;
	top=1;
	data[1]=1;
	for (i=2;i<=num;i++){
		while (top&&g[i].height>i-data[top])
			lp[i]=lp[data[top]],top--;
		data[++top]=i;
	}
	top=1;
	data[1]=num;
	for (i=num-1;i>=1;i--){
		while (top&&g[i].height>data[top]-i)
			rp[i]=rp[data[top]],top--;
		data[++top]=i;
	}
	top=1;
	data[1]=1;
	for (i=0;i<=num;i++)
		f[i]=1e18;
	f[1]=g[1].cost;
	f[rp[1]]=g[1].cost;
	f[rp[2]]=min(f[rp[2]],g[1].cost+g[2].cost);
	for (i=2;i<=num;i++){
		p=search(lp[i]-1);
		if (p)
			f[i]=min(f[i],g[i].cost+f[p]);
		f[i]=min(f[i],g[i].cost+f[i-1]);
		if (lp[i]<=1)
			f[i]=min(f[i],g[i].cost);
		while (top&&f[i]<=f[data[top]])
			top--;
		data[++top]=i;
		f[rp[i+1]]=min(f[rp[i+1]],f[i]+g[i+1].cost);
	}
	printf("%lld\n",f[num]);
	return 0;
}