class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

d.r = e
n.z = g
b.q = d
e.q = d
g.z = n
assert e.q.r.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

d.r = e
n.z = g
b.q = d
e.q = d
g.z = n
assert e.q.r.q.r.txt == "e"