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

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

h = A("h")
m = B("m")
i = C("i")
e = D("e")
j = E("j")
a = A("a")
k = A("k")

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

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

h = A("h")
m = B("m")
i = C("i")
e = D("e")
j = E("j")
a = A("a")
k = A("k")

h.q = k
h.o = i
m.o = k
i.r = k
e.s = i
e.z = h
e.x = h
e.y = m
j.y = e
a.q = k
a.o = i
k.q = h
k.o = i
assert h.o.r.o.r.txt == "k"