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

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

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

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

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

a.t = d
a.v = d
a.o = d
a.z = k
j.r = d
d.r = j
d.s = b
d.x = b
i.x = b
m.r = j
m.s = b
m.x = a
k.x = a
b.t = m
b.v = m
b.z = i
b.o = d
f.x = a
assert m.s.o.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.z: D = None
        self.v: C = None
        self.o: C = None
        self.txt = txt

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

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

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

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

a.t = d
a.v = d
a.o = d
a.z = k
j.r = d
d.r = j
d.s = b
d.x = b
i.x = b
m.r = j
m.s = b
m.x = a
k.x = a
b.t = m
b.v = m
b.z = i
b.o = d
f.x = a
assert m.s.o.r.r.r.r.txt == "d"