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

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

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

j = A("j")
a = B("a")
e = C("e")
m = B("m")
h = C("h")
d = A("d")
k = C("k")

j.y = d
j.o = e
a.z = m
a.o = k
a.r = j
e.r = d
e.z = a
m.z = a
m.o = k
m.r = j
h.r = j
h.z = m
d.y = j
d.o = e
k.r = j
k.z = a
assert e.r.y.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.o: C = None
        self.txt = txt

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

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

j = A("j")
a = B("a")
e = C("e")
m = B("m")
h = C("h")
d = A("d")
k = C("k")

j.y = d
j.o = e
a.z = m
a.o = k
a.r = j
e.r = d
e.z = a
m.z = a
m.o = k
m.r = j
h.r = j
h.z = m
d.y = j
d.o = e
k.r = j
k.z = a
assert e.r.y.o.z.txt == "a"