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

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

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

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

c = A("c")
m = B("m")
e = C("e")
b = D("b")
d = D("d")
i = D("i")
n = B("n")
a = B("a")
h = A("h")

c.y = a
c.p = e
m.o = i
m.p = a
m.t = c
e.p = a
b.x = a
b.r = d
d.x = a
d.r = i
i.x = n
i.r = b
n.o = b
n.p = m
n.t = h
a.o = d
a.p = m
a.t = h
h.y = a
h.p = e
assert m.o.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: C = None
        self.txt = txt

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

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

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

c = A("c")
m = B("m")
e = C("e")
b = D("b")
d = D("d")
i = D("i")
n = B("n")
a = B("a")
h = A("h")

c.y = a
c.p = e
m.o = i
m.p = a
m.t = c
e.p = a
b.x = a
b.r = d
d.x = a
d.r = i
i.x = n
i.r = b
n.o = b
n.p = m
n.t = h
a.o = d
a.p = m
a.t = h
h.y = a
h.p = e
assert m.o.r.r.x.txt == "a"