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

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

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

c = A("c")
g = B("g")
n = C("n")
b = A("b")
d = B("d")

c.z = d
g.t = n
n.q = d
b.z = g
d.t = n
assert g.t.q.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

c = A("c")
g = B("g")
n = C("n")
b = A("b")
d = B("d")

c.z = d
g.t = n
n.q = d
b.z = g
d.t = n
assert g.t.q.t.q.t.txt == "n"