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

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

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

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

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

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

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

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

e.o = k
e.q = f
f.z = k
f.x = e
f.w = n
k.x = f
c.o = n
c.q = f
n.x = f
d.o = k
d.q = f
assert n.x.z.x.x.txt == "e"