#K85912. Friend Recommendation System

    ID: 36747 Type: Default 1000ms 256MiB

Friend Recommendation System

Friend Recommendation System

You are given a social network with \(N\) users (indexed from 0 to \(N-1\)). Each user has a list of friends. Your task is to recommend new friends to every user based on their friends' connections.

For a given user \(i\), any user \(j\) (where \(j \neq i\)) is a candidate recommendation if \(j\) is a friend of any friend of \(i\) and is not already directly connected to \(i\). The recommendations for each user should be output in ascending order.

The input contains multiple test cases. Use the provided input format and output format exactly.

inputFormat

The first line contains an integer (T) ((1 \le T \le 100)) representing the number of test cases. For each test case, the input is as follows:

  1. An integer (N) ((1 \le N \le 1000)) denoting the number of users.
  2. Then (N) lines follow. The (i)-th line starts with an integer (F_i) (the number of friends for user (i)), followed by (F_i) space-separated integers representing the friend IDs. (User IDs range from 0 to (N-1)).

outputFormat

For each test case, output (N) lines. The (i)-th line should contain the recommended friend IDs for user (i) in ascending order, separated by a single space. If no recommendations exist for a user, output an empty line.## sample

1
4
2 1 2
2 0 3
2 0 3
2 1 2
3

2 1 0

</p>