<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

406. Goggle
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



Everybody knows search engine Goggle. But only advanced users know that it is possible to search number sequences. You can enter a set of numbers and the search engine will find all sequences which contain it. Goggle developers decided to improve the engine. New feature will help you if you know numbers which shouldn't be in the result. These numbers must be entered with the opposite sign. For example, if somebody enters "5 -3 6", the engine will find all the sequences which contain 5 and 6, but do not contain 3.

Help Goggle developers to implement the feature.

Input
The first line of the input will contain two integer numbers n and m (1 ≤ n ≤ 10, 1 ≤ m ≤ 10), where n is the number of sequences in Goggle database and m is the number of queries. Following n lines describe sequences in the Goggle database. The first integer k in each line is the length of the sequence (1 ≤ k ≤ 10). Next k numbers are the sequence elements. All of them are integers between 1 and 100, inclusive. Following m lines describe queries. The first integer l of each line is the numbers in query (1 ≤ l ≤ 10). Next l numbers bi are the sequence elements (1 ≤ |bi| ≤ 100, bi ≠ 0). These numbers have different absolute values.

Output
For each query print t — the number of found sequences on a separate line. Each of the next t lines should contain found sequence. The relative order of sequences should be preserved (in compliance with the input). The order of numbers in sequences should not change (in compliance with the input). Write sequences in format as they were given in the input.

Example(s)
sample input
sample output
3 5
6 1 2 3 1 2 3
4 3 2 4 5
2 4 2
3 1 2 3
2 3 2
3 2 -1 3
2 4 -2
2 4 5
1
6 1 2 3 1 2 3
2
6 1 2 3 1 2 3
4 3 2 4 5
1
4 3 2 4 5
0
1
4 3 2 4 5

<|response|>
1. Abridged Problem Statement  
You have n stored integer sequences (1 ≤ n ≤ 10), each of length up to 10, with elements in [1,100]. Then you receive m queries (1 ≤ m ≤ 10). Each query consists of a list of signed integers b₁,…,bₗ (1 ≤ l ≤ 10). A positive bᵢ means “this number must appear” and a negative bᵢ means “its absolute value must not appear.” For each query, output how many of the stored sequences satisfy all these requirements, and then list those sequences in their original format and input order.

2. Key Observations  
- Constraints are very small (n, m, k, l ≤ 10), so a simple brute-force check for each query against each sequence is more than fast enough.  
- To test membership quickly, store for each sequence both:  
  • The original list of its elements (for output).  
  • A hash‐set (or boolean array of size 101) marking which elements it contains.  
- For each query and for each sequence, iterate through the query terms:  
  • If bᵢ > 0 and bᵢ is not in the sequence, reject.  
  • If bᵢ < 0 and |bᵢ| is in the sequence, reject.  
  Otherwise accept.  

3. Full Solution Approach  
- Read n and m.  
- For i from 1 to n:  
  • Read kᵢ and then the kᵢ elements of sequence i.  
  • Store them in a vector seq[i].  
  • Also record a set or boolean array has[i][x] = true for fast lookup.  
- For each of the m queries:  
  • Read l and then the l signed integers b₁…bₗ.  
  • Initialize an empty list of matches.  
  • For each sequence i=1…n:  
    – Assume ok = true.  
    – For each b in the query list:  
      · If b > 0 and has[i][b] is false, set ok = false and break.  
      · If b < 0 and has[i][−b] is true, set ok = false and break.  
    – If ok remains true, append i to matches.  
  • Print the number of matches. Then for each matched index i, print the original sequence in the form “kᵢ x₁ x₂ … xₖᵢ.”  

Time complexity per query: O(n·l), which is at most 100 operations here—trivial.

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    // Store sequences and membership flags
    vector<vector<int>> seq(n);
    vector<array<bool, 101>> has(n);
    for (int i = 0; i < n; i++) {
        has[i].fill(false);
        int k;
        cin >> k;
        seq[i].resize(k);
        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            seq[i][j] = x;
            has[i][x] = true;  // mark that sequence i contains x
        }
    }

    // Process each query
    for (int qi = 0; qi < m; qi++) {
        int l;
        cin >> l;
        vector<int> query(l);
        for (int i = 0; i < l; i++) {
            cin >> query[i];
        }

        // Find matching sequences
        vector<int> matches;
        for (int i = 0; i < n; i++) {
            bool ok = true;
            for (int b : query) {
                if (b > 0) {
                    // required element missing?
                    if (!has[i][b]) { ok = false; break; }
                } else {
                    // forbidden element present?
                    if (has[i][-b]) { ok = false; break; }
                }
            }
            if (ok) {
                matches.push_back(i);
            }
        }

        // Output results for this query
        cout << matches.size() << "\n";
        for (int idx : matches) {
            cout << seq[idx].size();
            for (int x : seq[idx]) {
                cout << " " << x;
            }
            cout << "\n";
        }
    }

    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
import sys

def main():
    data = sys.stdin.read().split()
    it = iter(data)
    n, m = int(next(it)), int(next(it))

    # Read and store each sequence and its element‐set
    seq = []
    has = []
    for _ in range(n):
        k = int(next(it))
        s = []
        sset = set()
        for __ in range(k):
            x = int(next(it))
            s.append(x)
            sset.add(x)
        seq.append(s)
        has.append(sset)

    out_lines = []
    # Process queries
    for _ in range(m):
        l = int(next(it))
        query = [int(next(it)) for __ in range(l)]

        matches = []
        # Check each sequence
        for i in range(n):
            valid = True
            sset = has[i]
            for b in query:
                if b > 0:
                    # required number missing?
                    if b not in sset:
                        valid = False
                        break
                else:
                    # forbidden number present?
                    if -b in sset:
                        valid = False
                        break
            if valid:
                matches.append(i)

        # Record output
        out_lines.append(str(len(matches)))
        for idx in matches:
            s = seq[idx]
            out_lines.append(str(len(s)) + " " + " ".join(map(str, s)))

    sys.stdout.write("\n".join(out_lines))

if __name__ == "__main__":
    main()
```