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

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

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

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

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

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

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

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

e.q = d
b.x = g
d.x = c
d.z = n
c.x = f
g.x = c
g.z = n
f.x = b
f.z = n
n.q = g
assert d.x.x.x.txt == "b"