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

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

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

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

k.z = b
f.o = e
e.q = n
e.t = k
e.y = g
g.o = e
c.o = e
n.q = e
n.t = k
n.y = f
b.z = k
assert c.o.y.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

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

k.z = b
f.o = e
e.q = n
e.t = k
e.y = g
g.o = e
c.o = e
n.q = e
n.t = k
n.y = f
b.z = k
assert c.o.y.o.y.txt == "g"