#include<bits/stdc++.h>

#define x first
#define y second
#define y0 hi1
#define y1 hi2
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(a) (a)*(a)
#define ld long double
#define all(a) (a).begin(), (a).end()

using namespace std;

const int inf = 2e9;
const int N = 200 * 65 + 1;
const int M = 200 * 19 + 1;
const int K = 205;

int dp[2][K][M];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, kk;
    cin >> n >> kk;

    pair<int, int> a[n];
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;

        pair<int, int> val;
        while(x % 2 == 0){
            x /= 2;
            val.x++;
        }
        while(x % 5 == 0){
            x /= 5;
            val.y++;
        }

        a[i] = val;
    }

    for(int k = 0; k <= kk; k++){
        for(int j = 0; j < M; j++){
            for(int p = 0; p < 2; p++){
                dp[p][k][j] = -1;
            }
        }
    }
    dp[0][0][0] = dp[1][0][0] = 0;

    for(int i = 0; i < n; i++){

        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = 0; y < M - a[i].y; y++){
                if(dp[0][k - 1][y] != -1){
                    dp[1][k][y + a[i].y] = max(dp[1][k][y + a[i].y], dp[0][k - 1][y] + a[i].x);
                }
            }
        }

        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1; y >= 0; y--){
                dp[0][k][y] = max(dp[0][k][y], dp[1][k][y]);
            }
        }
    }

    int ans = 0;
    for(int y = M - 1; y > ans; y--){
        ans = max(ans, min(y, dp[0][kk][y]));
    }
    cout << ans;
}

/*
2 2
20 50
*/


#include<bits/stdc++.h>

#define x first
#define y second
#define y0 hi1
#define y1 hi2
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(a) (a)*(a)
#define ld long double
#define all(a) (a).begin(), (a).end()

using namespace std;

const int inf = 2e9;
const int N = 200 * 65 + 1;
const int M = 200 * 19 + 1;
const int K = 202;

int dp[2][K][M];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, kk;
    cin >> n >> kk;

    pair<int, int> a[n];
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;

        pair<int, int> val;
        while(x % 2 == 0){
            x /= 2;
            val.x++;
        }
        while(x % 5 == 0){
            x /= 5;
            val.y++;
        }

        a[i] = val;
    }

    for(int k = 0; k <= kk; k++){
        for(int j = 0; j < M; j++){
            for(int p = 0; p < 2; p++){
                dp[p][k][j] = -1;
            }
        }
    }
    dp[0][0][0] = dp[1][0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1; y >= 0; y--){
                if(dp[0][k - 1][y] != -1){
                    dp[1][k][y + a[i].y] = max(dp[1][k][y + a[i].y], dp[0][k - 1][y] + a[i].x);
                }
            }
        }

        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1; y >= 0; y--){
                dp[0][k][y] = dp[1][k][y];
            }
        }
    }

    int ans = 0;
    for(int y = M - 1; y > ans; y--){
        ans = max(ans, min(y, dp[0][kk][y]));
    }
    cout << ans;
}

/*
2 2
20 50
*/


#include<bits/stdc++.h>

#define x first
#define y second
#define y0 hi1
#define y1 hi2
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(a) (a)*(a)
#define ld long double
#define all(a) (a).begin(), (a).end()

using namespace std;

const int inf = 2e9;
const int N = 200 * 65 + 1;
const int M = 200 * 19 + 1;
const int K = 205;

int dp[2][K][M];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, kk;
    cin >> n >> kk;

    pair<int, int> a[n];
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;

        pair<int, int> val;
        while(x % 2 == 0){
            x /= 2;
            val.x++;
        }
        while(x % 5 == 0){
            x /= 5;
            val.y++;
        }

        a[i] = val;
    }

    for(int k = 0; k <= kk; k++){
        for(int j = 0; j < M; j++){
            for(int p = 0; p < 2; p++){
                dp[p][k][j] = -1;
            }
        }
    }
    dp[0][0][0] = dp[1][0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1 - a[i].y; y >= 0; y--){
                if(dp[0][k - 1][y] != -1){
                    dp[1][k][y + a[i].y] = max(dp[1][k][y + a[i].y], dp[0][k - 1][y] + a[i].x);
                }
            }
        }

        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1; y >= 0; y--){
                dp[0][k][y] = dp[1][k][y];
            }
        }
    }

    int ans = 0;
    for(int y = M - 1; y > ans; y--){
        ans = max(ans, min(y, dp[0][kk][y]));
    }
    cout << ans;
}

/*
2 2
20 50
*/


#include<bits/stdc++.h>

#define x first
#define y second
#define y0 hi1
#define y1 hi2
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(a) (a)*(a)
#define ld long double
#define all(a) (a).begin(), (a).end()

using namespace std;

const int inf = 2e9;
const int N = 200 * 64 + 1;
const int M = 200 * 18 + 1;
const int K = 201;

int dp[2][K][M];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, kk;
    cin >> n >> kk;

    pair<int, int> a[n];
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;

        pair<int, int> val;
        while(x % 2 == 0){
            x /= 2;
            val.x++;
        }
        while(x % 5 == 0){
            x /= 5;
            val.y++;
        }

        a[i] = val;
    }

    for(int k = 0; k <= kk; k++){
        for(int j = 0; j < M; j++){
            for(int p = 0; p < 2; p++){
                dp[p][k][j] = -1;
            }
        }
    }
    dp[0][0][0] = dp[1][0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1; y >= 0; y--){
                if(dp[0][k - 1][y] != -1){
                    dp[1][k][y + a[i].y] = max(dp[1][k][y + a[i].y], dp[0][k - 1][y] + a[i].x);
                }
            }
        }

        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1; y >= 0; y--){
                dp[0][k][y] = dp[1][k][y];
            }
        }
    }

    int ans = 0;
    for(int y = M - 1; y > ans; y--){
        ans = max(ans, min(y, dp[0][kk][y]));
    }
    cout << ans;
}

/*
2 2
20 50
*/


#include<bits/stdc++.h>

#define x first
#define y second
#define y0 hi1
#define y1 hi2
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(a) (a)*(a)
#define ld long double
#define all(a) (a).begin(), (a).end()

using namespace std;

const int inf = 2e9;
const int N = 200 * 65 + 1;
const int M = 200 * 19 + 1;
const int K = 205;

int dp[2][K][M];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, kk;
    cin >> n >> kk;

    pair<int, int> a[n];
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;

        pair<int, int> val;
        while(x % 2 == 0){
            x /= 2;
            val.x++;
        }
        while(x % 5 == 0){
            x /= 5;
            val.y++;
        }

        a[i] = val;
    }

    for(int k = 0; k <= kk; k++){
        for(int j = 0; j < M; j++){
            for(int p = 0; p < 2; p++){
                dp[p][k][j] = -1;
            }
        }
    }
    dp[0][0][0] = dp[1][0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1; y >= 0; y--){
                if(dp[0][k - 1][y] != -1 && y + a[i].y < M){
                    dp[1][k][y + a[i].y] = max(dp[1][k][y + a[i].y], dp[0][k - 1][y] + a[i].x);
                }
            }
        }

        for(int k = 1; k <= min(kk, i + 1); k++){
            for(int y = M - 1; y >= 0; y--){
                dp[0][k][y] = dp[1][k][y];
            }
        }
    }

    int ans = 0;
    for(int y = M - 1; y > ans; y--){
        ans = max(ans, min(y, dp[0][kk][y]));
    }
    cout << ans;
}

/*
2 2
20 50
*/


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
long long A[MAXN];
struct r{
    int v2, v5;

}G[205];
int Dp[205][6005];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;
    int sol = 0, c5=0, c2=0;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        long long tmp = A[i];
        while( tmp % 2==0 ) tmp /= 2, v2 ++;

        tmp = A[i];
        while( tmp % 5==0 ) tmp /= 5, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
        c2 += v2;
    }

    int tmp = 0;

    if( c5 < c2 ){
        for( int i = 1; i <= n; i ++ ){
              if( G[i].v2+G[i].v5 <= 0 ) continue;
        tmp += G[i].v5;

        for( int l = min( k, i ) ; l >= 1; l -- )
            for( int j = G[i].v5; j <= tmp; j ++ ){
                Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5]+G[i].v2 );
                sol = max( sol, min( j, Dp[l][j] ) );
            }
        }
    }else{
        for( int i = 1; i <= n; i ++ ){
              if( G[i].v2+G[i].v5 <= 0 ) continue;
         tmp += G[i].v2;

        for( int l = min( k, i ) ; l >= 1; l -- )
            for( int j = G[i].v2; j <= tmp; j ++ ){
                Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v2]+G[i].v5 );
                sol = max( sol, min( j, Dp[l][j] ) );
            }
        }
    }

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
int A[MAXN];
struct r{
    int v2, v5;

}G[205];
int Dp[205][6005];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;
    int sol = 0, c5=0;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        int tmp = A[i];
        while( tmp % 2==0 ) tmp /= 2, v2 ++;

        tmp = A[i];
        while( tmp % 5==0 ) tmp /= 5, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
    }
    int tmp = 0;
    for( int i = 1; i <= n; i ++ ){
          if( G[i].v2+G[i].v5 <= 0 ) continue;
    tmp += G[i].v5;
    for( int l = min( k, i ) ; l >= 1; l -- )
        for( int j = G[i].v5; j <= tmp; j ++ ){
            Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5]+G[i].v2 );
            sol = max( sol, min( j, Dp[l][j] ) );
        }
    }

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
long long A[MAXN];
struct r{
    int v2, v5;

}G[205];
int Dp[205][10005];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;
    int sol = 0, c5=0, c2=0;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        long long tmp = A[i];
        while( tmp % 2ll==0 ) tmp /= 2ll, v2 ++;

        tmp = A[i];
        while( tmp % 5ll==0 ) tmp /= 5ll, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
        c2 += v2;
    }

        for( int i = 1; i <= n; i ++ ){
              //if( G[i].v2+G[i].v5 <= 0 ) continue;

            for( int l = k; l >= 1; l -- )
                for( int j = c5; j >= G[i].v5; j -- ){

                    Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5]+G[i].v2 );

                    sol = max( sol, min( j, Dp[l][j] ) );
                }
        }

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
int A[MAXN], B[MAXN];
bool mark[MAXN][20005];

struct r{
    int v2, v5;

}G[205];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;

    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];
        B[i] = i;
        int v2 = 0, v5 = 0;
        int tmp = A[i];
        while( tmp % 2==0 ) tmp /= 2, v2 ++;
        tmp = A[i];
        while( tmp % 5==0 ) tmp /= 5, v5 ++;
        G[i].v2 = v2, G[i].v5 = v5;
    }

    /*mark[0][0] = true;
    for( int i = 1; i <= n; i ++ ){
        int v2 = 0, v5 = 0;
        int tmp = A[i];
        while( tmp % 2==0 ) tmp /= 2, v2 ++;
        tmp = A[i];
        while( tmp % 5==0 ) tmp /= 5, v5 ++;

        for( int i2 = 0; i2 <= 65; i2 ++ )
            for( int i5 = 0; i5 <= 65; i5 ++ )
            if( mark[i][i2][i5] ){
                mark[i][i2+v2]+[v5]
            }

    }

    for( int i = 1; i <= n; i ++ )*/

    int sol = 0, c = 100000, c2, c5;
    do{
       c2 = 0, c5 = 0;
       for( int i = 1; i <= k; i ++ ){
            c2 +=  G[B[i]].v2;
            c5 +=  G[B[i]].v5;
       }

       sol = max( sol, min( c2, c5 ) );

        random_shuffle( B+1, B+1+n );
    }while( c -- );

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
int A[MAXN];
struct r{
    int v2, v5;

}G[205];
int Dp[205][6005];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;
    int sol = 0, c5=0;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        int tmp = A[i];
        while( tmp % 2==0 ) tmp /= 2, v2 ++;

        tmp = A[i];
        while( tmp % 5==0 ) tmp /= 5, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
    }
    for( int i = 1; i <= n; i ++ )
    for( int l = k; l >= 1; l -- )
        for( int j = G[i].v5; j <= c5; j ++ ){
            Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5]+G[i].v2 );
            sol = max( sol, min( j, Dp[l][j] ) );
        }

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k;
long long A[MAXN];
struct r{
    int v2, v5;
}G[205];
int Dp[205][10005];
int sol = 0, c5=0, c2=0;

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        long long tmp = A[i];
        while( tmp % 2ll==0 )
            tmp /= 2ll, v2 ++;

        tmp = A[i];
        while( tmp % 5ll==0 )
            tmp /= 5ll, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
        c2 += v2;
    }

        for( int i = 1; i <= n; i ++ )
            for( int l = k; l >= 1; l -- )
                for( int j = c5; j >= G[i].v5; j -- ){

                    Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5] + G[i].v2 );

                    sol = max( sol, min( j, Dp[l][j] ) );
                }

    cout << sol << endl;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
int A[MAXN];
struct r{
    int v2, v5;

}G[205];
int Dp[205][6005];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;
    int sol = 0, c5=0, c2=0;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        int tmp = A[i];
        while( tmp % 2==0 ) tmp /= 2, v2 ++;

        tmp = A[i];
        while( tmp % 5==0 ) tmp /= 5, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
        c2 += v2;
    }

    int tmp = 0;

    if( c5 < c2 ){
        for( int i = 1; i <= n; i ++ ){
              if( G[i].v2+G[i].v5 <= 0 ) continue;
        tmp += G[i].v5;

        for( int l = min( k, i ) ; l >= 1; l -- )
            for( int j = G[i].v5; j <= tmp; j ++ ){
                Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5]+G[i].v2 );
                sol = max( sol, min( j, Dp[l][j] ) );
            }
        }
    }else{
        for( int i = 1; i <= n; i ++ ){
              if( G[i].v2+G[i].v5 <= 0 ) continue;
         tmp += G[i].v2;

        for( int l = min( k, i ) ; l >= 1; l -- )
            for( int j = G[i].v2; j <= tmp; j ++ ){
                Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v2]+G[i].v5 );
                sol = max( sol, min( j, Dp[l][j] ) );
            }
        }

    }

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
long long A[MAXN];
struct r{
    int v2, v5;

}G[205];
int Dp[205][6005];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;
    int sol = 0, c5=0, c2=0;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        long long tmp = A[i];
        while( tmp % 2ll==0 ) tmp /= 2ll, v2 ++;

        tmp = A[i];
        while( tmp % 5ll==0 ) tmp /= 5ll, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
        c2 += v2;
    }

        for( int i = 1; i <= n; i ++ ){
              if( G[i].v2+G[i].v5 <= 0 ) continue;

            for( int l = k; l >= 1; l -- )
                for( int j = G[i].v5; j <= c5; j ++ ){

                    Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5]+G[i].v2 );

                    sol = max( sol, min( j, Dp[l][j] ) );
                }
        }

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k;
long long A[MAXN];
struct r{
    int v2, v5;
}G[205];
int Dp[205][10005];
int sol = 0, c5=0, c2=0;

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        long long tmp = A[i];
        while( tmp % 2ll==0 )
            tmp /= 2ll, v2 ++;

        tmp = A[i];
        while( tmp % 5ll==0 )
            tmp /= 5ll, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
        c2 += v2;
    }

    memset(Dp, -1, sizeof(Dp));
        Dp[0][0] = 0;
        for( int i = 1; i <= n; i ++ )
            for( int l = k; l >= 1; l -- )
                for( int j = c5; j >= G[i].v5; j -- ){
                    if( Dp[l-1][j-G[i].v5] == -1 ) continue;
                    Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5] + G[i].v2 );

                    sol = max( sol, min( j, Dp[l][j] ) );
                }

    cout << sol << endl;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
long long A[MAXN];
struct r{
    int v2, v5;
}G[205];
int Dp[205][10005];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;
    int sol = 0, c5=0, c2=0;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        long long tmp = A[i];
        while( tmp % 2ll==0 )
            tmp /= 2ll, v2 ++;

        tmp = A[i];
        while( tmp % 5ll==0 )
            tmp /= 5ll, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
        c2 += v2;
    }

        for( int i = 1; i <= n; i ++ )
            for( int l = k; l >= 1; l -- )
                for( int j = c5; j >= G[i].v5; j -- ){
                    Dp[l][j] = max( Dp[l-1][j], Dp[l][j] );
                    Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5] + G[i].v2 );

                    sol = max( sol, min( j, Dp[l][j] ) );
                }

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
int A[MAXN], B[MAXN];
bool mark[MAXN][20005];

struct r{
    int v2, v5;

}G[205];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;

    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];
        B[i] = i;
        int v2 = 0, v5 = 0;
        int tmp = A[i];
        while( tmp % 2==0 ) tmp /= 2, v2 ++;
        tmp = A[i];
        while( tmp % 5==0 ) tmp /= 5, v5 ++;
        G[i].v2 = v2, G[i].v5 = v5;
    }

    /*mark[0][0] = true;
    for( int i = 1; i <= n; i ++ ){
        int v2 = 0, v5 = 0;
        int tmp = A[i];
        while( tmp % 2==0 ) tmp /= 2, v2 ++;
        tmp = A[i];
        while( tmp % 5==0 ) tmp /= 5, v5 ++;

        for( int i2 = 0; i2 <= 65; i2 ++ )
            for( int i5 = 0; i5 <= 65; i5 ++ )
            if( mark[i][i2][i5] ){
                mark[i][i2+v2]+[v5]
            }

    }

    for( int i = 1; i <= n; i ++ )*/

    int sol = 0, c = 1000000, c2, c5;
    do{
       c2 = 0, c5 = 0;
       for( int i = 1; i <= k; i ++ ){
            c2 +=  G[B[i]].v2;
            c5 +=  G[B[i]].v5;
       }

       sol = max( sol, min( c2, c5 ) );

        random_shuffle( B+1, B+1+n );
    }while( c -- );

    cout << sol;

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 205

using namespace std;

int n, k, t;
long long A[MAXN];
struct r{
    int v2, v5;

}G[205];
int Dp[205][6005];

int main() {
    #ifdef acm
        freopen("a.in", "r", stdin);
    #endif

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> k;
    int sol = 0, c5=0, c2=0;
    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];

        int v2 = 0, v5 = 0;

        long long tmp = A[i];
        while( tmp % 2ll==0 ) tmp /= 2ll, v2 ++;

        tmp = A[i];
        while( tmp % 5ll==0 ) tmp /= 5ll, v5 ++;

        G[i].v2 = v2, G[i].v5 = v5;
        c5 += v5;
        c2 += v2;
    }

    int tmp1 = 0;

    //if( c5 < c2 ){
        for( int i = 1; i <= n; i ++ ){
              if( G[i].v2+G[i].v5 <= 0 ) continue;
                tmp1 += G[i].v5;

            for( int l = k; l >= 1; l -- )
                for( int j = G[i].v5; j <= c5; j ++ ){
                    Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v5]+G[i].v2 );
                    sol = max( sol, min( j, Dp[l][j] ) );
                }
        }
   /* }else{
        for( int i = 1; i <= n; i ++ ){
              if( G[i].v2+G[i].v5 <= 0 ) continue;
         tmp1 += G[i].v2;

        for( int l = min( k, i ) ; l >= 1; l -- )
            for( int j = G[i].v2; j <= tmp1; j ++ ){
                Dp[l][j] = max( Dp[l][j], Dp[l-1][j-G[i].v2]+G[i].v5 );
                sol = max( sol, min( j, Dp[l][j] ) );
            }
        }
    }*/

    cout << sol;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define N 400000
#define M 1000000
using namespace std;
int n,m,x,id,cnt,col[N],tr[N],L[N],R[N];
int las[N],pre[N],K[N][2],ans[M];
map<pair<int,int>,int> has;
struct node{
    int l,r,id;
}q[M];
int query(int x){
    int ans=0;
    for (; x; x-=x&-x)
		ans+=tr[x];
    return ans;
}
void add(int x,int y){
    if (!x) return;
    for (; x<=cnt; x+=x&-x)
		tr[x]+=y;
}
bool cmp(node a,node b){
    return a.r==b.r?a.l<b.l:a.r<b.r;
}
void mp(int x,int y){
    pair<int,int> P=make_pair(x,y);
	int G=__gcd(abs(P.first),abs(P.second));
    P.first/=G;
	P.second/=G;
    if (!has.count(P))
		has[P]=++id;
    col[++cnt]=has[P];
}
int main(){
	scanf("%d",&n);
    for (int i=1; i<=n; i++){
		scanf("%d",&x);
        L[i]=cnt+1;
		R[i]=L[i]+x-1;
        for (int j=1; j<=x; j++){
			scanf("%d",&K[j][0]);
			scanf("%d",&K[j][1]);
        }
        for (int j=2; j<=x; j++){
            mp(K[j][1]-K[j-1][1],K[j][0]-K[j-1][0]);
        }
		mp(K[1][1]-K[R[i]-L[i]+1][1],K[1][0]-K[R[i]-L[i]+1][0]);
    }
    scanf("%d",&m);
    for (int i=1; i<=m; i++){
        q[i].id=i;
    	scanf("%d",&x);
		q[i].l=L[x];
    	scanf("%d",&x);
		q[i].r=R[x];
    }
    for (int i=1; i<=cnt; i++){
        pre[i]=las[col[i]];
		las[col[i]]=i;
    }
    sort(q+1,q+1+m,cmp);
    for (int tmp=1,i=1; i<=m; i++){
        for (;tmp<=q[i].r;tmp++){
        	add(tmp,1);
			add(pre[tmp],-1);
		}
        ans[q[i].id]=query(q[i].r)-query(q[i].l-1);
    }
    for (int i=1; i<=m; i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=300030;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
struct ques{
	int l,r,id;
	bool operator<(const ques &q)const{return r<q.r;}
}q[maxn];
struct seg{
	int x,y,d;
	bool operator<(const seg &s)const{
		if(x!=s.x) return x<s.x;
		if(y!=s.y) return y<s.y;
		return d<s.d;
	}
};
int n,Q,ans[maxn],tmpx[maxn],tmpy[maxn],bit[maxn];
vector<seg> v[maxn];
map<seg,int> at;
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
void update(int p,int v){for(int i=p;i<=n;i+=i&-i) bit[i]+=v;}
int query(int p){int s=0;for(int i=p;i;i-=i&-i) s+=bit[i];return s;}
int query(int l,int r){return query(r)-query(l-1);}
int main(){
	n=read();
	FOR(i,1,n){
		int k=read();
		FOR(j,1,k) tmpx[j]=read(),tmpy[j]=read();
		FOR(j,1,k){
			int dx=tmpx[j]-tmpx[j==1?k:j-1],dy=tmpy[j]-tmpy[j==1?k:j-1],tp=0;
			if(dx<0 || dx==0 && dy<0) tp=1;
			int g=gcd(dx,dy);
			dx/=g;dy/=g;
			if(dx<0 || dx==0 && dy<0) dx=-dx,dy=-dy;
			v[i].push_back((seg){dx,dy,tp});
		}
	}
	Q=read();
	FOR(i,1,Q){
		int l=read(),r=read();
		q[i]=(ques){l,r,i};
	}
	sort(q+1,q+Q+1);
	int cur=1;
	FOR(i,1,Q){
		while(cur<=q[i].r){
			FOR(j,0,(int)v[cur].size()-1){
				if(at[v[cur][j]]) update(at[v[cur][j]],-1);
				update(at[v[cur][j]]=cur,1);
			}
			cur++;
		}
		ans[q[i].id]=query(q[i].l,q[i].r);
	}
	FOR(i,1,Q) printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
struct ques{
	int l,r,id;
	bool operator<(const ques &q)const{return r<q.r;}
}q[maxn];
struct seg{
	int x,y,d;
	bool operator<(const seg &s)const{
		if(x!=s.x) return x<s.x;
		if(y!=s.y) return y<s.y;
		return d<s.d;
	}
};
int n,Q,ans[maxn],tmpx[maxn],tmpy[maxn],bit[maxn];
vector<seg> v[maxn];
map<seg,int> at;
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
void update(int p,int v){for(int i=p;i<=n;i+=i&-i) bit[i]+=v;}
int query(int p){int s=0;for(int i=p;i;i-=i&-i) s+=bit[i];return s;}
int query(int l,int r){return query(r)-query(l-1);}
int main(){
	n=read();
	FOR(i,1,n){
		int k=read();
		FOR(j,1,k) tmpx[j]=read(),tmpy[j]=read();
		FOR(j,1,k){
			int dx=tmpx[j]-tmpx[j==1?k:j-1],dy=tmpy[j]-tmpy[j==1?k:j-1],tp=0;
			if(dx<0 || dx==0 && dy<0) tp=1;
			int g=gcd(dx,dy);
			dx/=g;dy/=g;
			if(dx<0 || dx==0 && dy<0) dx=-dx,dy=-dy;
			v[i].push_back((seg){dx,dy,tp});
		}
	}
	Q=read();
	FOR(i,1,Q){
		int l=read(),r=read();
		q[i]=(ques){l,r,i};
	}
	sort(q+1,q+Q+1);
	int cur=1;
	FOR(i,1,Q){
		while(cur<=q[i].r){
			FOR(j,0,(int)v[cur].size()-1){
				if(at[v[cur][j]]) update(at[v[cur][j]],-1);
				update(at[v[cur][j]]=cur,1);
			}
			cur++;
		}
		ans[q[i].id]=query(q[i].l,q[i].r);
	}
	FOR(i,1,Q) printf("%d\n",ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
using ii = pair<int,int>;

int n, q, v;
vector<int> sz;
vector<ii> range;
vector<vector<ii>> pol;
map<ii,int> last_index;
vector<map<int,int>> ft;
vector<map<int,int>> pref_sum;

inline int lsb(int x){
	return x & -x;
}

int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a % b);
}

ii reduce(int a, int b){
	int _a = a, _b = b;
	if(_a < 0) _a = -_a;
	if(_b < 0) _b = -_b;

	if(a == 0) return ii(0, b / _b);
	if(b == 0) return ii(a / _a, 0);

	int g = gcd(max(_a, _b), min(_a, _b));
	return ii(a / g, b / g);
}

void range_update(int left, int right){
	++left;
	++right;

	int tmp = left;
	while(tmp <= v){
		ft[tmp][right]++;
		tmp += lsb(tmp);
	}
	tmp = right + 1;
	while(tmp <= v){
		ft[tmp][right]--;
		tmp += lsb(tmp);
	}
}

int query(int left, int right){
	++left;
	++right;

	int tmp = left;
	int ans = 0;
	while(tmp){
		auto it = pref_sum[tmp].upper_bound(right);
		if(it != pref_sum[tmp].begin()) ans += (--it)->second;
		tmp -= lsb(tmp);
	}

	return ans;
}

void add_line(ii line, int this_ind){
	int start_ind = last_index[line];
	last_index[line] = this_ind + 1;

	range_update(start_ind, this_ind);
}

void build(){
	for(int i = 1; i <= v; ++i){
		int sum = 0;
		for(auto it = ft[i].begin(); it != ft[i].end(); ++it){
			sum += it->second;
			pref_sum[i][it->first] = sum;
		}
	}
}

int main(){
	scanf("%d", &n);
	pol.resize(n); sz.resize(n); range.resize(n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &sz[i]);
		pol[i].resize(sz[i]);
		for(int j = 0; j < sz[i]; ++j, ++v) scanf("%d %d", &pol[i][j].first, &pol[i][j].second);
	}

	ft.resize(v + 1);
	pref_sum.resize(v + 1);

	int line_index = 0;
	for(int i = 0; i < n; ++i){
		range[i].first = line_index;
		for(int j = 0; j < sz[i]; ++j){
			int k = (j + 1) % sz[i];
			int dx = pol[i][k].first - pol[i][j].first;
			int dy = pol[i][k].second - pol[i][j].second;
			add_line(reduce(dx, dy), line_index);
			++line_index;
		}
		range[i].second = line_index - 1;
	}

	build();

	scanf("%d", &q);
	for(int i = 0, left, right; i < q; ++i){
		scanf("%d %d", &left, &right);
		--left; --right;
		left = range[left].first;
		right = range[right].second;
		int ans = 0;
		ans += query(left, right);
		printf("%d\n", ans);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ii = pair<int,int>;

int n, q, v;
vector<int> sz;
vector<ii> range;
vector<vector<ii>> pol;
map<ii,int> last_index;
vector<map<int,int>> ft;

inline int lsb(int x){
	return x & -x;
}

int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a % b);
}

ii reduce(int a, int b){
	int _a = a, _b = b;
	if(_a < 0) _a = -_a;
	if(_b < 0) _b = -_b;

	if(a == 0) return ii(0, b / _b);
	if(b == 0) return ii(a / _a, 0);

	int g = gcd(max(_a, _b), min(_a, _b));
	return ii(a / g, b / g);
}

void range_update(int left, int right){
	++left;
	++right;

	int tmp = left;
	while(tmp <= v){
		ft[tmp][right]++;
		tmp += lsb(tmp);
	}
	tmp = right + 1;
	while(tmp <= v){
		ft[tmp][right]--;
		tmp += lsb(tmp);
	}
}

int query(int left, int right){
	++left;
	++right;

	int tmp = left;
	int ans = 0;
	while(tmp){
		auto it = ft[tmp].upper_bound(right);
		if(it != ft[tmp].begin()) ans += (--it)->second;
		tmp -= lsb(tmp);
	}

	return ans;
}

void add_line(ii line, int this_ind){
	int start_ind = last_index[line];
	last_index[line] = this_ind + 1;

	range_update(start_ind, this_ind);
}

void build(){
	for(int i = 1; i <= v; ++i){
		int sum = 0;
		for(auto &it: ft[i]){
			sum += it.second;
			it.second = sum;
		}
	}
}

int main(){
	scanf("%d", &n);
	pol.resize(n); sz.resize(n); range.resize(n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &sz[i]);
		pol[i].resize(sz[i]);
		for(int j = 0; j < sz[i]; ++j, ++v) scanf("%d %d", &pol[i][j].first, &pol[i][j].second);
	}

	ft.resize(v + 1);

	int line_index = 0;
	for(int i = 0; i < n; ++i){
		range[i].first = line_index;
		for(int j = 0; j < sz[i]; ++j){
			int k = (j + 1) % sz[i];
			int dx = pol[i][k].first - pol[i][j].first;
			int dy = pol[i][k].second - pol[i][j].second;
			add_line(reduce(dx, dy), line_index);
			++line_index;
		}
		range[i].second = line_index - 1;
	}

	build();

	scanf("%d", &q);
	for(int i = 0, left, right; i < q; ++i){
		scanf("%d %d", &left, &right);
		--left; --right;
		left = range[left].first;
		right = range[right].second;
		int ans = 0;
		ans += query(left, right);
		printf("%d\n", ans);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ii = pair<int,int>;

int n, q, v;
vector<int> sz;
vector<ii> range;
vector<vector<ii>> pol;
map<ii,int> last_index;
vector<vector<ii>> ft;

inline int lsb(int x){
	return x & -x;
}

int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a % b);
}

ii reduce(int a, int b){
	int _a = a, _b = b;
	if(_a < 0) _a = -_a;
	if(_b < 0) _b = -_b;

	if(a == 0) return ii(0, b / _b);
	if(b == 0) return ii(a / _a, 0);

	int g = gcd(max(_a, _b), min(_a, _b));
	return ii(a / g, b / g);
}

int binary_search(int ind, int val){
	int lb = -1, ub = ft[ind].size() - 1;
	while(lb < ub){
		int mid = (lb + ub + 1) >> 1;
		if(ft[ind][mid].first > val) ub = mid - 1;
		else lb = mid;
	}
	if(lb == -1) return 0;
	return ft[ind][lb].second;
}

int query(int left, int right){
	++left;
	++right;

	int tmp = left;
	int ans = 0;
	while(tmp){
		ans += binary_search(tmp, right);
		tmp -= lsb(tmp);
	}

	return ans;
}

void range_update(int left, int right){
	++left;
	++right;

	int tmp = left;
	while(tmp <= v){
		ft[tmp].push_back(ii(right, 1));
		tmp += lsb(tmp);
	}
	tmp = right + 1;
	while(tmp <= v){
		ft[tmp].push_back(ii(right, -1));
		tmp += lsb(tmp);
	}
}

void add_line(ii line, int this_ind){
	int start_ind = last_index[line];
	last_index[line] = this_ind + 1;

	range_update(start_ind, this_ind);
}

void build(){
	for(int i = 1; i <= v; ++i){
		sort(ft[i].begin(), ft[i].end());
		vector<ii> tmp;
		int sum = 0;
		for(int j = 0; j < ft[i].size(); ++j){
			sum += ft[i][j].second;
			if(j == ft[i].size() - 1 || ft[i][j].first != ft[i][j + 1].first)
				tmp.push_back(ii(ft[i][j].first, sum));
		}
		ft[i] = tmp;
	}
}

int main(){
	scanf("%d", &n);
	pol.resize(n); sz.resize(n); range.resize(n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &sz[i]);
		pol[i].resize(sz[i]);
		for(int j = 0; j < sz[i]; ++j, ++v) scanf("%d %d", &pol[i][j].first, &pol[i][j].second);
	}

	ft.resize(v + 1);

	int line_index = 0;
	for(int i = 0; i < n; ++i){
		range[i].first = line_index;
		for(int j = 0; j < sz[i]; ++j){
			int k = (j + 1) % sz[i];
			int dx = pol[i][k].first - pol[i][j].first;
			int dy = pol[i][k].second - pol[i][j].second;
			add_line(reduce(dx, dy), line_index);
			++line_index;
		}
		range[i].second = line_index - 1;
	}

	build();

	scanf("%d", &q);
	for(int i = 0, left, right; i < q; ++i){
		scanf("%d %d", &left, &right);
		--left; --right;
		left = range[left].first;
		right = range[right].second;
		int ans = 0;
		ans += query(left, right);
		printf("%d\n", ans);
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;
const int maxn = 3e5 + 5;

class Vector{
public:
	ldb x, y;
	inline Vector(){}
	inline Vector(int _x, int _y): x(_x), y(_y){
		if(x){
			y /= abs(x);
			x /= abs(x);
		}
		else
			(y /= abs(y)) *= INF;
		return;
	}
	bool operator < (const Vector &oth)const{ return MP(x, y) < MP(oth.x, oth.y); }
}slp[maxn];

int n, m, q;
int s[maxn], ans[maxn];
vector<pii> qry[maxn];
map<Vector, int> mp;

class FenwickTree{
private:
	inline void update(int x, int k){
		for(++x; x <= n; x += x & (-x)){
			dat[x] += k;
		}
		return;
	}
public:
	int dat[maxn];
	inline void update(int l, int r, int k){
		if(l > r)
			return;
		update(l, k);
		update(r + 1, -k);
		return;
	}
	inline int query(int x){
		int ret = 0;
		for(++x; x; x -= x & (-x))
			ret += dat[x];
		return ret;
	}
}fen;

int main(){
	scanf("%d", &n);
	FOR(i, 0, n){
		int k;
		scanf("%d", &k);
		s[i] = m;
		int x, y, nx, ny, sx, sy;
		FOR(j, 0, k){
			scanf("%d%d", &nx, &ny);
			if(j)
				slp[m++] = Vector(x - nx, y - ny);
			else
				sx = nx, sy =ny;
			x = nx, y = ny;
		}
		slp[m++] = Vector(x - sx, y - sy);
	}
	s[n] = m;
	scanf("%d", &q);
	FOR(i, 0, q){
		int l, r;
		scanf("%d%d", &l, &r);
		--l; --r;
		qry[r].PB(MP(l, i));
	}
	for(int i = 0, j = 0; i < n; ++i){
		for(; j < s[i + 1]; ++j){
			int pos = (mp.find(slp[j]) != mp.end()) ? mp[slp[j]] : -1;
			fen.update(pos + 1, i, 1);
			mp[slp[j]] = i;
		}
		FOR(x, 0, qry[i].size()){
			ans[qry[i][x].snd] = fen.query(qry[i][x].fst);
		}
	}
	FOR(i, 0, q)
		printf("%d ", ans[i]);
	puts("");
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;
const int maxn = 3e5 + 5;

class Vector{
public:
	db x, y;
	inline Vector(){}
	inline Vector(int _x, int _y): x(_x), y(_y){
		if(x){
			y /= abs(x);
			x /= abs(x);
		}
		else
			(y /= abs(y)) *= INF;
		return;
	}
	bool operator < (const Vector &oth)const{ return MP(x, y) < MP(oth.x, oth.y); }
}slp[maxn];

int n, m, q;
int s[maxn], ans[maxn];
vector<pii> qry[maxn];
map<Vector, int> mp;

class FenwickTree{
private:
	inline void update(int x, int k){
		for(++x; x <= n; x += x & (-x)){
			dat[x] += k;
		}
		return;
	}
public:
	int dat[maxn];
	inline void update(int l, int r, int k){
		if(l > r)
			return;
		update(l, k);
		update(r + 1, -k);
		return;
	}
	inline int query(int x){
		int ret = 0;
		for(++x; x; x -= x & (-x))
			ret += dat[x];
		return ret;
	}
}fen;

int main(){
	scanf("%d", &n);
	FOR(i, 0, n){
		int k;
		scanf("%d", &k);
		s[i] = m;
		int x, y, nx, ny, sx, sy;
		FOR(j, 0, k){
			scanf("%d%d", &nx, &ny);
			if(j)
				slp[m++] = Vector(x - nx, y - ny);
			else
				sx = nx, sy =ny;
			x = nx, y = ny;
		}
		slp[m++] = Vector(x - sx, y - sy);
	}
	s[n] = m;
	scanf("%d", &q);
	FOR(i, 0, q){
		int l, r;
		scanf("%d%d", &l, &r);
		--l; --r;
		qry[r].PB(MP(l, i));
	}
	for(int i = 0, j = 0; i < n; ++i){
		for(; j < s[i + 1]; ++j){
			int pos = (mp.find(slp[j]) != mp.end()) ? mp[slp[j]] : -1;
			fen.update(pos + 1, i, 1);
			mp[slp[j]] = i;
		}
		FOR(x, 0, qry[i].size()){
			ans[qry[i][x].snd] = fen.query(qry[i][x].fst);
		}
	}
	FOR(i, 0, q)
		printf("%d ", ans[i]);
	puts("");
	return 0;
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<10;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来/
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int main(){
	int n =read();
	for(int i =0; i < n; ++i){
		int k =read();
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
	int S =sqrt(Q*2.0/3);
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =q[i].l/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(--l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < Q; ++i)
		write(ans[i]), putchar('\n');
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<18;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来 //
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int pre[MAXN];

int main(){
	int n =read();
	for(int i =0; i < n; ++i){
		int k =read();
		pre[i+1] =pre[i]+k;
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
//	int S =sqrt(Q*2.0/3);
	int S =sqrt(1.0*pre[n]*pre[n]/Q);
	if(S == 0)/*<<- */
		S =1;
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =/*q[i].l/S*/ pre[q[i].l+1]/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(--l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < Q; ++i)
		write(ans[i]), putchar('\n');
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<10;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来/
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int main(){
	int n =read();
	for(int i =0; i < n; ++i){
		int k =read();
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
	int S =sqrt(Q*2.0/3);
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =q[i].l/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(--l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < n; ++i)
		write(ans[i]), putchar('\n');
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<10;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来/
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int main(){
	int n =read();
	int sum_v =0;
	for(int i =0; i < n; ++i){
		int k =read();
		sum_v +=k;
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
//	int S =sqrt(Q*2.0/3);
	int S =sqrt(1.0*sum_v*sum_v/Q);
	if(S == 0)/*<<- */
		S =1;
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =q[i].l/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(--l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < Q; ++i)
		write(ans[i]), putchar('\n');
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<10;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来/
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int pre[MAXN];

int main(){
	int n =read();
	for(int i =0; i < n; ++i){
		int k =read();
		pre[i+1] =pre[i]+k;
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
//	int S =sqrt(Q*2.0/3);
	int S =sqrt(1.0*pre[n]*pre[n]/Q);
	if(S == 0)/*<<- */
		S =1;
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =/*q[i].l/S*/ pre[q[i].l+1]/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(--l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < Q; ++i)
		write(ans[i]), putchar('\n');
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<10;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来/
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int main(){
	int n =read();
	for(int i =0; i < n; ++i){
		int k =read();
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
	int S =sqrt(Q*2.0/3);
	if(S == 0)/*<<- */
		S =1;
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =q[i].l/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(--l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < Q; ++i)
		write(ans[i]), putchar('\n');
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<10;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来/
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int main(){
	int n =read();
	for(int i =0; i < n; ++i){
		int k =read();
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
//	int S =sqrt(Q*2.0/3);
	int S =sqrt(1.0*tot*tot/Q);
	if(S == 0)/*<<- */
		S =1;
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =q[i].l/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(--l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < Q; ++i)
		write(ans[i]), putchar('\n');
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<10;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来/
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int main(){
	int n =read();
	for(int i =0; i < n; ++i){
		int k =read();
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
	int S =sqrt(Q*2.0/3);
	if(S < 0)/*<<- */
		S =1;
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =q[i].l/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(--l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < Q; ++i)
		write(ans[i]), putchar('\n');
}


#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using std::vector;
using std::map;
using std::pair;
using std::sort;

const int MAXN =1e5+20, MAXK =4e5+20;

/*------------------------------IO------------------------------*/

namespace MyIO{
	const int MAXB =1<<10;
	char gbuf[MAXB], *ps =gbuf, *pt =gbuf;
	char pbuf[MAXB+1], *pp =pbuf;
	struct Flusher{
		~Flusher(){
			fwrite(pbuf, 1, pp-pbuf, stdout);
		}
	}flusher;

	inline char Getchar(){
		if(ps == pt){
			ps =gbuf;
			pt =gbuf+fread(gbuf, 1, MAXB, stdin);
		}
		return (ps == pt) ? EOF : *ps++;
	}
	inline void Putchar(const char &ch){
		if(pp == pbuf+MAXB){
			pp =pbuf;
			fwrite(pbuf, 1, MAXB, stdout);
		}
		*pp++ =ch;
	}
}
#define getchar MyIO::Getchar
#define putchar MyIO::Putchar

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

void write(const int &x){
	if(x/10)
		write(x/10);
	putchar('0'+x%10);
}

/*------------------------------Pre------------------------------*/

int gcd(int a, int b){
	while(b ^=a ^=b ^=a %=b) ;
	return a;
}

inline int Abs(const int &x){ return (x < 0) ? -x : x; }

struct line{
	int k_up, k_down;/*斜率分子分母*/

	line(){}
	line(const int &KU, const int &KD){
		if(KU == 0 || KD == 0){
			k_up =(KU != 0) ? ((KU > 0) ? 1 : -1) : 0;
			k_down =(KD != 0) ? ((KD > 0) ? 1 : -1) : 0;
		}
		else{
			// 向量的不同朝向会在分子分母的符号中体现出来/
			int Gcd =Abs(gcd(KU, KD));
			k_up =KU/Gcd;
			k_down =KD/Gcd;
		//	if(k_down < 0)
		//		k_up =-k_up, k_down =-k_down;
		}
	}

	bool operator < (const line &B) const{/*仅用于 map 做区分*/
		if(k_up == B.k_up)
			return k_down < B.k_down;
		else
			return k_up < B.k_up;
	}
};

int tot;
map<line, int> Map;

/*------------------------------莫队------------------------------*/

vector<int> poly[MAXN];

struct query{
	int l, r, cl, id;

	bool operator < (const query &B) const{
		if(cl == B.cl)
			return (cl&1) ? r < B.r : r > B.r;
		else
			return cl < B.cl;
	}
}q[MAXN];

int cnt[MAXK];
int Ans;

void add(const int &pos){
	for(int col:poly[pos])
		if(++cnt[col] == 1)
			++Ans;
}

void del(const int &pos){
	for(int col:poly[pos])
		if(--cnt[col] == 0)
			--Ans;
}

/*------------------------------Main------------------------------*/

int ans[MAXN];

int main(){
	int n =read();
	for(int i =0; i < n; ++i){
		int k =read();
		int s_x =read(), s_y =read();
		int pre_x =s_x, pre_y =s_y;
		for(int j =0; j < k-1; ++j){
			int x =read(), y =read();
			line l =line(y-pre_y, x-pre_x);
			if(Map.count(l))
				poly[i].push_back(Map.find(l)->second);
			else{
				poly[i].push_back(++tot);
				Map.insert(pair<line, int>(l, tot));
			}
			pre_x =x, pre_y =y;
		}
		line l =line(s_y-pre_y, s_x-pre_x);
		if(Map.count(l))
			poly[i].push_back(Map.find(l)->second);
		else{
			poly[i].push_back(++tot);
			Map.insert(pair<line, int>(l, tot));
		}
	}

	int Q =read();
	int S =sqrt(Q*2.0/3);
	for(int i =0; i < Q; ++i){
		q[i].l =read()-1, q[i].r =read()-1;
		q[i].id =i, q[i].cl =q[i].l/S;
	}
	sort(q, q+Q);
	for(int i =0, l =0, r =0; i < Q; ++i){
		while(l < q[i].l) del(l++);
		while(l > q[i].l) add(++l);
		while(r < q[i].r+1) add(r++);
		while(r > q[i].r+1) del(--r);
		ans[q[i].id] =Ans;
	}

	for(int i =0; i < n; ++i)
		write(ans[i]), putchar('\n');
}


#include <cctype>
#include <cstdio>
#include <cstring>
#include <algorithm>

#define DEBUG(args...) fprintf(stderr, args)

typedef long long LL;

#define FOR(i, l, r) for(int i = (l), i##_end = (r); i <= i##_end; ++i)
#define REP(i, l, r) for(int i = (l), i##_end = (r); i <  i##_end; ++i)
#define DFR(i, l, r) for(int i = (l), i##_end = (r); i >= i##_end; --i)
#define DRP(i, l, r) for(int i = (l), i##_end = (r); i >  i##_end; --i)

template<class T>T Min(const T &a, const T &b) {return a < b ? a : b;}
template<class T>T Max(const T &a, const T &b) {return a > b ? a : b;}
template<class T>bool Chkmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T>bool Chkmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

struct fast_input {
	static const int L = 1 << 15 | 1;
	char buf[L], *l, *r;
	fast_input() {l = r = buf;}
	void Next(char &c) {
		if(l == r) r = (l = buf) + fread(buf, 1, L, stdin);
		c = l == r ? (char)EOF : *l++;
	}
	template<class T>void operator () (T &x) {
		char c, f = 0;
		for(Next(c); !isdigit(c); Next(c)) if(c == '-') f = 1;
		for(x = 0; isdigit(c); Next(c)) x = x * 10 + c - '0';
		if(f) x = -x;
	}
}input;

const int N = 100000 + 7;
const int LN = 10000000 + 7;
const int M = 300000 + 7;

int rot[N], lch[LN], rch[LN], sz[LN], cnt;
std::pair<int, int> d[M], a[M], b[M];
int n, m, c[M], t[N], lst[M];

int gcd(int x, int y) {
	return !y ? x : gcd(y, x % y);
}

int modify(int rt, int l, int r, int p, int x) {
	int i = ++cnt;
	sz[i] = sz[rt] + x, lch[i] = lch[rt], rch[i] = rch[rt];
	if(l == r) {return i;}
	int mid = l + r >> 1;
	if(p <= mid) lch[i] = modify(lch[rt], l, mid, p, x);
	else rch[i] = modify(rch[rt], mid + 1, r, p, x);
	return i;
}

int ask(int rt, int l, int r, int p) {
	if(l == p) return sz[rt];
	int mid = l + r >> 1;
	if(p <= mid) return ask(lch[rt], l, mid, p) + sz[rch[rt]];
	else return ask(rch[rt], mid + 1, r, p);
}

int main() {

#ifdef Cai
	freopen("s.in", "r", stdin);
#endif

	int x, y, z, g;

	input(n);
	FOR(i, 1, n) {
		input(x), t[i] = m = m + x;
		FOR(j, t[i - 1] + 1, t[i])
			input(d[j].first), input(d[j].second);
		d[t[i] + 1] = d[t[i - 1] + 1];
		FOR(j, t[i - 1] + 1, t[i]) {
			y = d[j].first - d[j + 1].first;
			z = d[j].second - d[j + 1].second;
			if(y && z) g = gcd(std::abs(y), std::abs(z));
			else g = std::abs(y) + std::abs(z);
			a[j] = b[j] = std::make_pair(y / g, z / g);
		}
	}

	std::sort(a + 1, a + m + 1);
	m = std::unique(a + 1, a + m + 1) - a - 1;
	FOR(i, 1, t[n]) c[i] = std::lower_bound(a + 1, a + m + 1, b[i]) - a;

	FOR(i, 1, n) {
		rot[i] = rot[i - 1];
		FOR(j, t[i - 1] + 1, t[i]) {
			if(lst[c[j]]) rot[i] = modify(rot[i], 1, n, lst[c[j]], -1);
			rot[i] = modify(rot[i], 1, n, i, 1);
			lst[c[j]] = i;
		}
	}

	input(m);
	while(m--) {
		input(x), input(y);
		printf("%d\n", ask(rot[y], 1, n, x));
	}

	return 0;

}


#include <cctype>
#include <cstdio>
#include <cstring>
#include <algorithm>

#define DEBUG(args...) fprintf(stderr, args)

typedef long long LL;

#define FOR(i, l, r) for(int i = (l), i##_end = (r); i <= i##_end; ++i)
#define REP(i, l, r) for(int i = (l), i##_end = (r); i <  i##_end; ++i)
#define DFR(i, l, r) for(int i = (l), i##_end = (r); i >= i##_end; --i)
#define DRP(i, l, r) for(int i = (l), i##_end = (r); i >  i##_end; --i)

template<class T>T Min(const T &a, const T &b) {return a < b ? a : b;}
template<class T>T Max(const T &a, const T &b) {return a > b ? a : b;}
template<class T>bool Chkmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T>bool Chkmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

struct fast_input {
	static const int L = 1 << 15 | 1;
	char buf[L], *l, *r;
	fast_input() {l = r = buf;}
	void Next(char &c) {
		if(l == r) r = (l = buf) + fread(buf, 1, L, stdin);
		c = l == r ? (char)EOF : *l++;
	}
	template<class T>void operator () (T &x) {
		char c, f = 0;
		for(Next(c); !isdigit(c); Next(c)) if(c == '-') f = 1;
		for(x = 0; isdigit(c); Next(c)) x = x * 10 + c - '0';
		if(f) x = -x;
	}
}input;

const int N = 100000 + 7;
const int LN = 20000000 + 7;
const int M = 300000 + 7;

int rot[N], lch[LN], rch[LN], sz[LN], cnt;
std::pair<int, int> d[M], a[M], b[M];
int n, m, c[M], t[N], lst[M];

int gcd(int x, int y) {
	return !y ? x : gcd(y, x % y);
}

int modify(int rt, int l, int r, int p, int x) {
	int i = ++cnt;
	sz[i] = sz[rt] + x, lch[i] = lch[rt], rch[i] = rch[rt];
	if(l == r) {return i;}
	int mid = l + r >> 1;
	if(p <= mid) lch[i] = modify(lch[rt], l, mid, p, x);
	else rch[i] = modify(rch[rt], mid + 1, r, p, x);
	return i;
}

int ask(int rt, int l, int r, int p) {
	if(l == p) return sz[rt];
	int mid = l + r >> 1;
	if(p <= mid) return ask(lch[rt], l, mid, p) + sz[rch[rt]];
	else return ask(rch[rt], mid + 1, r, p);
}

int main() {

#ifdef Cai
	freopen("s.in", "r", stdin);
#endif

	int x, y, z, g;

	input(n);
	FOR(i, 1, n) {
		input(x), t[i] = m = m + x;
		FOR(j, t[i - 1] + 1, t[i])
			input(d[j].first), input(d[j].second);
		d[t[i] + 1] = d[t[i - 1] + 1];
		FOR(j, t[i - 1] + 1, t[i]) {
			y = d[j].first - d[j + 1].first;
			z = d[j].second - d[j + 1].second;
			if(y && z) g = gcd(std::abs(y), std::abs(z));
			else g = std::abs(y) + std::abs(z);
			a[j] = b[j] = std::make_pair(y / g, z / g);
		}
	}

	std::sort(a + 1, a + m + 1);
	m = std::unique(a + 1, a + m + 1) - a - 1;
	FOR(i, 1, t[n]) c[i] = std::lower_bound(a + 1, a + m + 1, b[i]) - a;

	FOR(i, 1, n) {
		rot[i] = rot[i - 1];
		FOR(j, t[i - 1] + 1, t[i]) {
			if(lst[c[j]]) rot[i] = modify(rot[i], 1, n, lst[c[j]], -1);
			rot[i] = modify(rot[i], 1, n, i, 1);
			lst[c[j]] = i;
		}
	}

	input(m);
	while(m--) {
		input(x), input(y);
		printf("%d\n", ask(rot[y], 1, n, x));
	}

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+7;
const double eps=1e-8,inf=1e16;
map<double,int> mp;
inline int dcom(double x){return x>eps?1:(x<-eps?-1:0);}
struct node{
	int x,y;double sn;
	node(int x=0,int y=0){this->x=x,this->y=y;}
	inline friend node operator - (const node a,const node b){return node(a.x-b.x,a.y-b.y);}
	inline friend long long operator * (const node a,const node b){return 1ll*a.x*b.y-1ll*a.y*b.x;}
	inline friend bool operator < (const node a,const node b){return dcom(a.sn-b.sn)?dcom(a.sn-b.sn)==-1:a.x<b.x;}
	inline void out(){cout<<x<<' '<<y<<' '<<sn<<endl;}
	inline double calc(){return 1.0*(y+eps)/(x+eps);}
}sta[maxn];
struct rem{
	int l,r,id;
	inline friend bool operator <(rem a,rem b){return a.r<b.r;}
}qr[maxn];
vector<node> c[maxn];
double cp[maxn];
int rd[maxn],b[maxn],tot,pre[maxn],ans[maxn];
inline void ins(int x,int y){
	if(x) for(int i=x;i<=tot;i+=i&-i) b[i]+=y;
}
inline int que(int x,int res=0){
	for(int i=x;i;i-=i&-i) res+=b[i];
	return res;
}
int main(){
	int n,top=0,q;cin>>n;
	for(int i=1;i<=n;++i){
		int k;scanf("%d",&k);c[i].resize(k);
		for(int j=0;j<k;++j) scanf("%d%d",&c[i][j].x,&c[i][j].y);
		node px=c[i][0];
		for(node &p:c[i]) if(p.x<px.x||(p.x==px.x&&p.y<px.y)) px=p,swap(p,c[i][0]);
		for(node &p:c[i]) p=p-px,p.sn=atan2(p.y,p.x);//p.out();puts("");
		sort(c[i].begin()+1,c[i].end());top=0;
		for(node p:c[i]) {
			while(top>1&&(sta[top]-sta[top-1])*(p-sta[top])<=0) --top;
			sta[++top]=p;
		}
		sta[++top]=sta[1];//cout<<top<<endl;
		for(int i=2;i<=top;++i) cp[++tot]=(sta[i]-sta[i-1]).calc();rd[i]=tot;
	}
	scanf("%d",&q);
	for(int i=1;i<=q;++i) scanf("%d%d",&qr[i].l,&qr[i].r),qr[i].id=i;
	for(int i=1;i<=tot;++i) pre[i]=mp[cp[i]],mp[cp[i]]=i;//,cerr<<i<<' '<<pre[i]<<' '<<cp[i]<<endl;
	sort(qr+1,qr+q+1);int tl=1;
	for(int i=1;i<=q;++i){
		while(tl<=qr[i].r) {
			for(int i=rd[tl-1]+1;i<=rd[tl];++i) ins(i,1),ins(pre[i],-1);
			++tl;
		}
		ans[qr[i].id]=que(tot)-que(rd[qr[i].l-1]);
	}
	for(int i=1;i<=q;++i) printf("%d\n",ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+7;
const double eps=0,inf=1e16;
map<double,int> mp;
inline int dcom(double x){return x>eps?1:(x<-eps?-1:0);}
struct node{
	int x,y;double sn;
	node(int x=0,int y=0){this->x=x,this->y=y;}
	inline friend node operator - (const node a,const node b){return node(a.x-b.x,a.y-b.y);}
	inline friend long long operator * (const node a,const node b){return 1ll*a.x*b.y-1ll*a.y*b.x;}
	inline friend bool operator < (const node a,const node b){return dcom(a.sn-b.sn)?dcom(a.sn-b.sn)==-1:a.x<b.x;}
	inline void out(){cout<<x<<' '<<y<<' '<<sn<<endl;}
	inline double calc(){return atan2(y,x);}
}sta[maxn];
struct rem{
	int l,r,id;
	inline friend bool operator <(rem a,rem b){return a.r<b.r;}
}qr[maxn];
vector<node> c[maxn];
double cp[maxn];
int rd[maxn],b[maxn],tot,pre[maxn],ans[maxn];
inline void ins(int x,int y){
	if(x) for(int i=x;i<=tot;i+=i&-i) b[i]+=y;
}
inline int que(int x,int res=0){
	for(int i=x;i;i-=i&-i) res+=b[i];
	return res;
}
int main(){
	int n,top=0,q;cin>>n;
	for(int i=1;i<=n;++i){
		int k;scanf("%d",&k);c[i].resize(k);
		for(int j=0;j<k;++j) scanf("%d%d",&c[i][j].x,&c[i][j].y);
		node px=c[i][0];
		for(node &p:c[i]) if(p.x<px.x||(p.x==px.x&&p.y<px.y)) px=p,swap(p,c[i][0]);
		for(node &p:c[i]) p=p-px,p.sn=atan2(p.y,p.x);//p.out();puts("");
		sort(c[i].begin()+1,c[i].end());top=0;
		for(node p:c[i]) {
			while(top>1&&(sta[top]-sta[top-1])*(p-sta[top])<=0) --top;
			sta[++top]=p;
		}
		sta[++top]=sta[1];
		for(int i=2;i<=top;++i) cp[++tot]=(sta[i]-sta[i-1]).calc();rd[i]=tot;
	}
	scanf("%d",&q);
	for(int i=1;i<=q;++i) scanf("%d%d",&qr[i].l,&qr[i].r),qr[i].id=i;
	for(int i=1;i<=tot;++i) pre[i]=mp[cp[i]],mp[cp[i]]=i;//,cerr<<i<<' '<<pre[i]<<' '<<cp[i]<<endl;
	sort(qr+1,qr+q+1);int tl=1;
	for(int i=1;i<=q;++i){
		while(tl<=qr[i].r) {
			for(int i=rd[tl-1]+1;i<=rd[tl];++i) ins(i,1),ins(pre[i],-1);
			++tl;
		}
		ans[qr[i].id]=que(tot)-que(rd[qr[i].l-1]);
	}
	for(int i=1;i<=q;++i) printf("%d\n",ans[i]);
	return 0;
}


#include<bits/stdc++.h>
#define double long double
using namespace std;
const int maxn=3e5+7;
const double eps=0,inf=1e16;
map<double,int> mp;
inline int dcom(double x){return x>eps?1:(x<-eps?-1:0);}
struct node{
	int x,y;double sn;
	node(int x=0,int y=0){this->x=x,this->y=y;}
	inline friend node operator - (const node a,const node b){return node(a.x-b.x,a.y-b.y);}
	inline friend long long operator * (const node a,const node b){return 1ll*a.x*b.y-1ll*a.y*b.x;}
	inline friend bool operator < (const node a,const node b){return dcom(a.sn-b.sn)?dcom(a.sn-b.sn)==-1:a.x<b.x;}
	inline double calc(){return atan2(1.0L*y,1.0L*x);}
}sta[maxn];
struct rem{
	int l,r,id;
	inline friend bool operator <(rem a,rem b){return a.r<b.r;}
}qr[maxn];
vector<node> c[maxn];
double cp[maxn];
int rd[maxn],b[maxn],tot,pre[maxn],ans[maxn];
inline void ins(int x,int y){
	if(x) for(int i=x;i<=tot;i+=i&-i) b[i]+=y;
}
inline int que(int x,int res=0){
	for(int i=x;i;i-=i&-i) res+=b[i];
	return res;
}
int main(){
	int n,top=0,q;cin>>n;
	for(int i=1;i<=n;++i){
		int k;scanf("%d",&k);c[i].resize(k);
		for(int j=0;j<k;++j) scanf("%d%d",&c[i][j].x,&c[i][j].y);
		node px=c[i][0];
		for(node &p:c[i]) if(p.x<px.x||(p.x==px.x&&p.y<px.y)) px=p,swap(p,c[i][0]);
		for(node &p:c[i]) p=p-px,p.sn=atan2(p.y,p.x);//p.out();puts("");
		sort(c[i].begin()+1,c[i].end());top=0;
		for(node p:c[i]) {
			while(top>1&&(sta[top]-sta[top-1])*(p-sta[top])<=0) --top;
			sta[++top]=p;
		}
		sta[++top]=sta[1];
		for(int i=2;i<=top;++i) cp[++tot]=(sta[i]-sta[i-1]).calc();rd[i]=tot;
	}
	scanf("%d",&q);
	for(int i=1;i<=q;++i) scanf("%d%d",&qr[i].l,&qr[i].r),qr[i].id=i;
	for(int i=1;i<=tot;++i) pre[i]=mp[cp[i]],mp[cp[i]]=i;//,cerr<<i<<' '<<pre[i]<<' '<<cp[i]<<endl;
	sort(qr+1,qr+q+1);int tl=1;
	for(int i=1;i<=q;++i){
		while(tl<=qr[i].r) {
			for(int i=rd[tl-1]+1;i<=rd[tl];++i) ins(i,1),ins(pre[i],-1);
			++tl;
		}
		ans[qr[i].id]=que(tot)-que(rd[qr[i].l-1]);
	}
	for(int i=1;i<=q;++i) printf("%d\n",ans[i]);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> point;

#define x first
#define y second

const int N = 3e5 + 10;
point polynomial[N], apoint[N];
map <point, int> position;
int pointer;
vector <pair <int, point>> quer;

int st[N], en[N], f[N], ans[N];

void update(int p, int v) {
  while (p < N){
	  f[p] += v;
	  p += p & -p;
  }
}

int pref(int p) {
  int ret = 0;
  while (p > 0){
	  ret += f[p];
	  p -= p & -p;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int k;
	scanf("%d", &k);

    for (int j = 1; j <= k; ++j) {
      scanf("%d %d", &polynomial[j].x, &polynomial[j].y);
    }
    polynomial[k + 1] = polynomial[1];
	st[i] = pointer + 1;
    for (int j = 1; j <= k; j++) {
		point p = point(polynomial[j + 1].x - polynomial[j].x, polynomial[j + 1].y - polynomial[j].y);
		if(p.x == 0) {
			if(p.y < 0){
				p.y = -1;
			}
			else{
				p.y = 1;
			}
		}
		if(p.y == 0) {
			if(p.x < 0){
				p.x = -1;
			}
			else{
				p.x = 1;
			}
		}
		int g = __gcd(abs(p.x), abs(p.y));
		p.x /= g;
		p.y /= g;
		apoint[pointer++] = p;
	}
    en[i] = pointer;
  }
  int q;
  cin >> q;
  for (int i = 1, l, r; i <= q; i++) {
    scanf("%d %d", &l, &r);
    quer.emplace_back(en[r], point(st[l], i));
  }
  sort(quer.begin(), quer.end());
  int at = 0;
  for (auto it : quer) {
    while (at < it.x) {
      point &p = apoint[at++];
      if (position.find(p) != position.end()){
		  update(position[p], -1);
	  }
      position[p] = at;
	  update(position[p], +1);
    }
	ans[it.y.y] = pref(it.x) - pref(it.y.x - 1);
  }
  for (int i = 1; i <= q; i++){
	  printf("%d\n", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> point;

#define x first
#define y second

const int N = 3e5 + 10;
point polynomial[N], apoint[N];
map <point, int> position;

int st[N], en[N], f[N], ans[N];

void update(int p, int v) {
  while (p < N){
	  f[p] += v;
	  p += p & -p;
  }
}

int pref(int p) {
  int ret = 0;
  while (p > 0){
	  ret += f[p];
	  p -= p & -p;
  }
  return ret;
}

int main() {

  vector <pair <int, point>> quer;
  int n;
  int pointer;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int k;
	scanf("%d", &k);

    for (int j = 1; j <= k; ++j) {
      scanf("%d %d", &polynomial[j].x, &polynomial[j].y);
    }
    polynomial[k + 1] = polynomial[1];
	st[i] = pointer + 1;
    for (int j = 1; j <= k; j++) {
		point p = point(polynomial[j + 1].x - polynomial[j].x, polynomial[j + 1].y - polynomial[j].y);
		if(p.x == 0) {
			if(p.y < 0){
				p.y = -1;
			}
			else{
				p.y = 1;
			}
		}
		if(p.y == 0) {
			if(p.x < 0){
				p.x = -1;
			}
			else{
				p.x = 1;
			}
		}
		int g = __gcd(abs(p.x), abs(p.y));
		p.x /= g;
		p.y /= g;
		apoint[pointer++] = p;
	}
    en[i] = pointer;
  }
  int q;
  cin >> q;
  for (int i = 1, l, r; i <= q; i++) {
    scanf("%d %d", &l, &r);
    quer.emplace_back(en[r], point(st[l], i));
  }
  sort(quer.begin(), quer.end());
  int at = 0;
  for (auto it : quer) {
    while (at < it.x) {
      point &p = apoint[at++];
      if (position.find(p) != position.end()){
		  update(position[p], -1);
	  }
      position[p] = at; update(position[p], +1);
    }
	ans[it.y.y] = pref(it.x) - pref(1 - it.y.x);
  }
  for (int i = 1; i <= q; i++){
	  printf("%d\n", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> point;

#define x first
#define y second

const int N = 3e5 + 10;
map <point, int> position;

int st[N], en[N], f[N], ans[N];

void update(int p, int v) {
  while (p < N){
	  f[p] += v;
	  p += p & -p;
  }
}

int pref(int p) {
  int ret = 0;
  while (p > 0){
	  ret += f[p];
	  p -= p & -p;
  }
  return ret;
}

int main() {
  point polynomial[N]
  point apoint[N];
  vector <pair <int, point>> quer;
  int n;
  int pointer;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int k;
	scanf("%d", &k);

    for (int j = 1; j <= k; ++j) {
      scanf("%d %d", &polynomial[j].x, &polynomial[j].y);
    }
    polynomial[k + 1] = polynomial[1];
	st[i] = pointer + 1;
    for (int j = 1; j <= k; j++) {
		point p = point(polynomial[j + 1].x - polynomial[j].x, polynomial[j + 1].y - polynomial[j].y);
		if(p.x == 0) {
			if(p.y < 0){
				p.y = -1;
			}
			else{
				p.y = 1;
			}
		}
		if(p.y == 0) {
			if(p.x < 0){
				p.x = -1;
			}
			else{
				p.x = 1;
			}
		}
		int g = __gcd(abs(p.x), abs(p.y));
		p.x /= g;
		p.y /= g;
		apoint[pointer++] = p;
	}
    en[i] = pointer;
  }
  int q;
  cin >> q;
  for (int i = 1, l, r; i <= q; i++) {
    scanf("%d %d", &l, &r);
    quer.emplace_back(en[r], point(st[l], i));
  }
  sort(quer.begin(), quer.end());
  int at = 0;
  for (auto it : quer) {
    while (at < it.x) {
      point &p = apoint[at++];
      if (position.find(p) != position.end()){
		  update(position[p], -1);
	  }
      position[p] = at; update(position[p], +1);
    }
	ans[it.y.y] = pref(it.x) - pref(1 - it.y.x);
  }
  for (int i = 1; i <= q; i++){
	  printf("%d\n", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> point;

#define x first
#define y second

const int N = 3e5 + 10;
point polynomial[N], apoint[N];
map <point, int> position;
int pointer;
vector <pair <int, point>> quer;

int st[N], en[N], f[N], ans[N];

void update(int p, int v) {
  while (p < N){
	  f[p] += v;
	  p += p & -p;
  }
}

int pref(int p) {
  int ret = 0;
  while (p > 0){
	  ret += f[p];
	  p -= p & -p;
  }
  return ret;
}

int main() {

  int n;

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int k;
	scanf("%d", &k);

    for (int j = 1; j <= k; ++j) {
      scanf("%d %d", &polynomial[j].x, &polynomial[j].y);
    }
    polynomial[k + 1] = polynomial[1];
	st[i] = pointer + 1;
    for (int j = 1; j <= k; j++) {
		point p = point(polynomial[j + 1].x - polynomial[j].x, polynomial[j + 1].y - polynomial[j].y);
		if(p.x == 0) {
			if(p.y < 0){
				p.y = -1;
			}
			else{
				p.y = 1;
			}
		}
		if(p.y == 0) {
			if(p.x < 0){
				p.x = -1;
			}
			else{
				p.x = 1;
			}
		}
		int g = __gcd(abs(p.x), abs(p.y));
		p.x /= g;
		p.y /= g;
		apoint[pointer++] = p;
	}
    en[i] = pointer;
  }
  int q;
  cin >> q;
  for (int i = 1, l, r; i <= q; i++) {
    scanf("%d %d", &l, &r);
    quer.emplace_back(en[r], point(st[l], i));
  }
  sort(quer.begin(), quer.end());
  int at = 0;
  for (auto it : quer) {
    while (at < it.x) {
      point &p = apoint[at++];
      if (position.find(p) != position.end()){
		  update(position[p], -1);
	  }
      position[p] = at; update(position[p], +1);
    }
	ans[it.y.y] = pref(it.x) - pref(1 - it.y.x);
  }
  for (int i = 1; i <= q; i++){
	  printf("%d\n", ans[i]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> point;

#define x first
#define y second

const int N = 3e5 + 10;
point polynomial[N]
point apoint[N];
map <point, int> position;

int st[N], en[N], f[N], ans[N];

void update(int p, int v) {
  while (p < N){
	  f[p] += v;
	  p += p & -p;
  }
}

int pref(int p) {
  int ret = 0;
  while (p > 0){
	  ret += f[p];
	  p -= p & -p;
  }
  return ret;
}

int main() {

  vector <pair <int, point>> quer;
  int n;
  int pointer;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int k;
	scanf("%d", &k);

    for (int j = 1; j <= k; ++j) {
      scanf("%d %d", &polynomial[j].x, &polynomial[j].y);
    }
    polynomial[k + 1] = polynomial[1];
	st[i] = pointer + 1;
    for (int j = 1; j <= k; j++) {
		point p = point(polynomial[j + 1].x - polynomial[j].x, polynomial[j + 1].y - polynomial[j].y);
		if(p.x == 0) {
			if(p.y < 0){
				p.y = -1;
			}
			else{
				p.y = 1;
			}
		}
		if(p.y == 0) {
			if(p.x < 0){
				p.x = -1;
			}
			else{
				p.x = 1;
			}
		}
		int g = __gcd(abs(p.x), abs(p.y));
		p.x /= g;
		p.y /= g;
		apoint[pointer++] = p;
	}
    en[i] = pointer;
  }
  int q;
  cin >> q;
  for (int i = 1, l, r; i <= q; i++) {
    scanf("%d %d", &l, &r);
    quer.emplace_back(en[r], point(st[l], i));
  }
  sort(quer.begin(), quer.end());
  int at = 0;
  for (auto it : quer) {
    while (at < it.x) {
      point &p = apoint[at++];
      if (position.find(p) != position.end()){
		  update(position[p], -1);
	  }
      position[p] = at; update(position[p], +1);
    }
	ans[it.y.y] = pref(it.x) - pref(1 - it.y.x);
  }
  for (int i = 1; i <= q; i++){
	  printf("%d\n", ans[i]);
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=300100;
int sm[N];
int a[N],b[N],n,q,ans[N],cnt,l[N],r[N],la[N];
map<pair<int,int>,int>mp;
vector<pair<int,int> >vec[N];
void add(int x,int y){for(;x;x-=x&-x)sm[x]+=y;}
int qry(int x){int ret=0;for(;x<=cnt;x+=x&-x)ret+=sm[x];return ret;}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
		int K;
		cin>>K;l[i]=cnt+1;
		for(int j=1;j<=K;++j)cin>>a[j]>>b[j];
		for(int j=1;j<=K;++j){
			++cnt;
			int x=a[j%K+1]-a[j],y=b[j%K+1]-b[j],g=abs(__gcd(x,y));
			x/=g;y/=g;if(mp.count(make_pair(x,y)))la[cnt]=mp[make_pair(x,y)];
			mp[make_pair(x,y)]=cnt;
		}
		r[i]=cnt;
	}
	cin>>q;
	for(int i=1;i<=q;++i){
		int x,y;cin>>x>>y;x=l[x];y=r[y];
		vec[y].emplace_back(x,i);
	}
	for(int i=1;i<=cnt;++i){
		add(la[i],-1);add(i,1);
		for(auto j:vec[i])
			ans[j.second]=qry(j.first);
	}
	for(int i=1;i<=q;++i)cout<<ans[i]<<'\n';
	return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    void clear() { *this = hash_map_t(mod); }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 3e5 + 5;

struct ele { int l, r, id; } q[N];

map <pii, int> wxw;
int l[N], r[N], col[N], x[N], y[N], B[N], ans[N], vis[N];
int n, Q, now, cnt, res;

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

inline void add(int x) {
    if(!vis[x]) ++res;
    ++vis[x];
}

inline void del(int x) {
    --vis[x];
    if(!vis[x]) --res;
}

bool operator < (const ele a, const ele b) {
    if(B[a.l] == B[b.l]) return a.r < b.r;
    return a.l < b.l;
}

int main() {
	read(n);
	for(register int i = 1; i <= n; i++) {
		int m; read(m); l[i] = now + 1; r[i] = now + m;
		for(register int j = 1; j <= m; j++) read(x[j]), read(y[j]);
		for(register int j = 1; j <= m; j++) {
			int fr = j == 1 ? m : j - 1;
			int _x = x[j] - x[fr], _y = y[j] - y[fr];
			// if(_x < 0) _x = -_x, _y = -_y;
			int d = gcd(abs(_x), abs(_y));
			_x /= d; _y /= d;
			if(!wxw.count(make_pair(_x, _y))) {
				++cnt;
				col[now + j] = cnt;
				wxw[make_pair(_x, _y)] = cnt;
			} else col[now + j] = wxw[make_pair(_x, _y)];
		}
		now += m;
	}
    // for(register int i = 1; i <= now; i++) fprintf(stderr, "%d\n", col[i]);
    int blk = floor(sqrt(now + 0.5)) + 1;
    for(register int i = 1; i <= now; i++) B[i] = (i - 1) / blk + 1;
    read(Q);
    for(register int i = 1; i <= Q; i++) read(q[i].l), read(q[i].r), q[i].l = l[q[i].l], q[i].r = r[q[i].r], q[i].id = i;
    sort(q + 1, q + Q + 1); int L = 1, R = 0;
    for(register int i = 1; i <= Q; i++) {
        while(R < q[i].r) add(col[++R]);
        while(L > q[i].l) add(col[--L]);
        while(R > q[i].r) del(col[R--]);
        while(L < q[i].l) del(col[L++]);
        ans[q[i].id] = res;
    }
    for(register int i = 1; i <= Q; i++) print(ans[i], '\n');
    return 0;
}


#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    void clear() { *this = hash_map_t(mod); }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 3e5 + 5;

map <pii, int> wxw;
vector <pii> q[N];
int l[N], r[N], pre[N], x[N], y[N], ans[N], f[N];
int n, Q, now, cnt, res;

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

inline int lowbit(int x) { return x & -x; }

inline void add(int x) {
    ++x;
    for(register int i = x; i <= now; i += lowbit(i)) ++f[i];
}

inline int query(int x) {
    ++x;
    int ans = 0;
    for(register int i = x; i; i ^= lowbit(i)) ans += f[i];
    return ans;
}

int main() {
    read(n);
    for(register int i = 1; i <= n; i++) {
        int m; read(m); l[i] = now + 1; r[i] = now + m;
        for(register int j = 1; j <= m; j++) read(x[j]), read(y[j]);
        for(register int j = 1; j <= m; j++) {
            int fr = j == 1 ? m : j - 1;
            int _x = x[j] - x[fr], _y = y[j] - y[fr];
            // if(_x < 0) _x = -_x, _y = -_y;
            int d = gcd(abs(_x), abs(_y));
            _x /= d; _y /= d;
            if(!wxw.count(make_pair(_x, _y))) wxw[make_pair(_x, _y)] = now + j;
            else pre[now + j] = wxw[make_pair(_x, _y)], wxw[make_pair(_x, _y)] = now + j;
        }
        now += m;
    }
    read(Q);
    for(register int i = 1; i <= Q; i++) {
        int l, r;
        read(l); read(r);
        l = ::l[l]; r = ::r[r];
        q[r].push_back(make_pair(l, i));
    }
    for(register int i = 1; i <= now; i++) {
        add(pre[i]);
        for(register int j = 0; j < (int)q[i].size(); j++) ans[q[i][j].second] = query(q[i][j].first - 1) - q[i][j].first + 1;
    }
    for(register int i = 1; i <= Q; i++) print(ans[i], '\n');
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
template<class T> inline void read(T &n){
    char ch=GC;T w=1,x=0;
    while(!isdigit(ch)){if(ch=='-') w=-1;ch=GC;}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=GC;}
    n=x*w;
}
const int maxn=100005;
const int maxm=300005;
int n,q,N,st[maxn],ed[maxn],X[maxm],Y[maxm];
pair <int,int> a[maxm];
map <pair<int,int>,int> lst;
int ans[maxn];
struct query{
	int l,r,id;
}Q[maxn];
bool cmp(query x,query y){
	return x.r<y.r;
}
int t[maxm];
inline int lowbit(int x){
	return x&(-x);
}
inline void update(int x,int val){
	for(int i=x;i<=N;i+=lowbit(i)) t[i]+=val;
}
inline int ask(int x){
	int res=0;
	for(int i=x;i>=1;i-=lowbit(i)) res+=t[i];
	return res;
}
int main(){
	read(n);
	for(int i=1,k;i<=n;i++){
		read(k);
		for(int j=1;j<=k;j++) read(X[j]),read(Y[j]);
		X[k+1]=X[1],Y[k+1]=Y[1];
		st[i]=ed[i-1]+1;
		ed[i]=ed[i-1];
		for(int j=1;j<=k;j++){
			int x=X[j+1]-X[j],y=Y[j+1]-Y[j];
			int g=__gcd(abs(x),abs(y));
			if(g) x/=g,y/=g;
			a[++ed[i]]=make_pair(x,y);
		}
	}
	N=ed[n];
	read(q);
	for(int i=1,l,r;i<=q;i++){
		read(l),read(r);
		Q[i]=(query){st[l],ed[r],i};
	}
	sort(Q+1,Q+q+1,cmp);
	for(int i=1,j=1;i<=N;i++){
		if(lst[a[i]]) update(lst[a[i]],-1);
		lst[a[i]]=i,update(i,1);
		for(;j<=q&&Q[j].r<=i;j++) ans[Q[j].id]=ask(Q[j].r)-ask(Q[j].l-1);
	}
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
	return 0;
}