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

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

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

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

a.z = e
e.q = a
f.t = e
f.q = e
g.t = e
g.q = e
assert g.q.q.z.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: A = None
        self.txt = txt

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

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

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