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

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

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

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

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

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

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