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

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

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

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

j = A("j")
f = B("f")
e = C("e")
k = D("k")
d = B("d")
a = D("a")
i = A("i")
c = B("c")
m = D("m")

j.o = i
f.w = j
e.r = c
e.x = c
k.w = i
d.w = j
a.w = i
i.o = j
c.w = j
m.w = j
assert d.w.o.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

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

j = A("j")
f = B("f")
e = C("e")
k = D("k")
d = B("d")
a = D("a")
i = A("i")
c = B("c")
m = D("m")

j.o = i
f.w = j
e.r = c
e.x = c
k.w = i
d.w = j
a.w = i
i.o = j
c.w = j
m.w = j
assert d.w.o.o.o.o.o.o.o.o.txt == "j"