class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.q: A = None
        self.p: D = None
        self.txt = txt

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

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

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

h = A("h")
l = B("l")
n = C("n")
d = D("d")
j = D("j")
i = C("i")
m = A("m")

h.r = j
h.p = j
h.q = m
l.p = h
n.z = l
n.q = l
n.p = h
n.o = j
d.y = n
j.y = i
i.z = l
i.q = l
i.p = m
i.o = j
m.r = d
m.q = h
m.p = j
assert j.y.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.q: A = None
        self.p: D = None
        self.txt = txt

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

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

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

h = A("h")
l = B("l")
n = C("n")
d = D("d")
j = D("j")
i = C("i")
m = A("m")

h.r = j
h.p = j
h.q = m
l.p = h
n.z = l
n.q = l
n.p = h
n.o = j
d.y = n
j.y = i
i.z = l
i.q = l
i.p = m
i.o = j
m.r = d
m.q = h
m.p = j
assert j.y.p.p.txt == "j"