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

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

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

e.t = g
e.z = g
f.q = e
g.q = e
assert g.q.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.z: B = None
        self.txt = txt

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

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

e.t = g
e.z = g
f.q = e
g.q = e
assert g.q.z.q.txt == "e"