Should we be friends? Note this is a question primarily focusing on data-structures
Introduction
Bacefook wants people to be friendlier! As such, they are implementing a new system to suggest friends! Your task is to help Bacefook to implement their new suggesting system.
Specifications:
Your program must be a REPL (read-eval-print loop) supporting 3 types of command: FRIEND, SUGGEST and KNOW.
FRIEND X Y - Specifies that X and Y are friends in the social network.

If X is friends with Y, then Y is friends with X

Can, but doesn't have to have output

X is always friends with X


KNOW X Y - Output a truthy value if X and Y are friends, falsy otherwise

KNOW X X will always output a truthy value

SUGGEST X Y - Output a truthy value if X and Y should be friends, falsy otherwise. X and Y should be friends if:

X and Y are not friends

X and Y have at least 1 friend in common


You are allowed to replace FRIEND, SUGGEST and KNOW with your own strings, but you must mention what string you have replaced each command with.
Your program can take in input/produce output in any way desirable, as long as it is reasonably easy to recognize how it works.
The number of people in the social network N is between 1 and 100,000, but there may be any number of &quot;friend links&quot; (edges).

 If you haven't noticed yet, this is a graph searching problem. The (likely) easiest (and possibly fastest) data structure to implement this in would be an adjacency matrix.

Test cases
FRIEND A B
FRIEND A C
FRIEND B D
SUGGEST A B -&gt; Falsy, as they are friends
SUGGEST A D -&gt; Truthy, as they share B as a common friend
SUGGEST C D -&gt; Falsy, they do not share a common friend
KNOW D B -&gt; Truthy, they are friends
KNOW B C -&gt; Falsy, not friends
=============
FRIEND Tom Tim
KNOW Tom Tim -&gt; Truthy
KNOW Tim Tom -&gt; Truthy
KNOW Tom Kit -&gt; Falsy
=============
KNOW Tim Kit -&gt; Falsy
FRIEND Tim Tom
KNOW Tim Kit -&gt; Falsy
FRIEND Tom Kit
SUGGEST Tim Kit -&gt; Truthy
=============
FRIEND X Y
SUGGEST X Y -&gt; Falsy since X is friends with X

Here's some more test cases in image form
Win condition
This is code-golf, shortest code wins!
SWI-Prolog, 62 47 41 bytes

X*Y:-X+Y;Y+X;X==Y.
X?Y:-not(X*Y),X*Z,Y*Z.


Prolog isn't too often useful, but when it is it's just beautiful. We'll use a+b to notate that a is friends with b, a*b that a knows b and a?b that b should be suggested to a or not. The first line simply says that X*Y is true if either X+Y, Y+X or X == Y is true. This implements the symmetry of knowing eachother. Asking if there should be a suggestion is incredibly simple. We just ask if there is a Z such that X*Y is false and X*Z and Y*Z is true. Exactly as described in the challenge.

If you save this as a file (e.g. friends.pl) and open SWI-Prolog with this file (prolog -l friends.pl) you get dropped into a REPL.

You can assert friendships like this:

assert('a' + 'b').
assert('a' + 'c').
assert('b' + 'd').


You can check if people know eachother or suggestion should be made:

'a'*'b'.
'a'?'d'.