class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

b = A("b")
f = B("f")
e = B("e")
g = A("g")

b.x = g
b.q = g
f.p = b
e.p = g
g.x = b
g.q = b
assert b.q.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

b = A("b")
f = B("f")
e = B("e")
g = A("g")

b.x = g
b.q = g
f.p = b
e.p = g
g.x = b
g.q = b
assert b.q.q.x.txt == "g"