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

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

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

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

d = A("d")
a = B("a")
c = C("c")
n = D("n")
j = D("j")
i = B("i")
m = C("m")

d.o = n
a.r = n
c.o = i
c.p = m
n.o = j
n.w = c
n.y = i
n.p = a
j.o = n
j.w = c
j.y = i
j.p = i
i.r = j
m.o = i
m.p = c
assert a.r.y.r.w.o.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

d = A("d")
a = B("a")
c = C("c")
n = D("n")
j = D("j")
i = B("i")
m = C("m")

d.o = n
a.r = n
c.o = i
c.p = m
n.o = j
n.w = c
n.y = i
n.p = a
j.o = n
j.w = c
j.y = i
j.p = i
i.r = j
m.o = i
m.p = c
assert a.r.y.r.w.o.r.o.txt == "n"