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

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

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

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

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

d.r = c
c.z = e
c.x = m
e.w = d
e.v = d
e.u = i
m.o = k
k.z = e
k.x = i
h.r = c
n.w = d
n.v = h
n.u = m
i.o = c
assert k.x.o.z.u.o.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

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

d.r = c
c.z = e
c.x = m
e.w = d
e.v = d
e.u = i
m.o = k
k.z = e
k.x = i
h.r = c
n.w = d
n.v = h
n.u = m
i.o = c
assert k.x.o.z.u.o.z.v.txt == "d"