class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.u: D = 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.x: A = None
        self.txt = txt

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

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

m.x = d
m.u = i
n.o = d
j.x = d
i.o = d
i.w = b
d.x = m
d.u = i
a.x = m
f.o = m
k.o = d
e.o = m
b.o = m
b.w = i
assert f.o.u.w.w.w.o.u.o.u.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.u: D = 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.x: A = None
        self.txt = txt

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

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

m.x = d
m.u = i
n.o = d
j.x = d
i.o = d
i.w = b
d.x = m
d.u = i
a.x = m
f.o = m
k.o = d
e.o = m
b.o = m
b.w = i
assert f.o.u.w.w.w.o.u.o.u.o.txt == "d"