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

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

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

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

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

d.r = k
c.r = n
c.x = i
c.u = k
c.y = d
k.s = i
k.o = c
n.r = m
n.o = h
n.t = i
h.s = i
h.o = i
i.r = n
i.x = c
i.u = k
i.y = d
m.r = n
m.o = h
m.t = i
assert k.o.r.o.s.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

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

d.r = k
c.r = n
c.x = i
c.u = k
c.y = d
k.s = i
k.o = c
n.r = m
n.o = h
n.t = i
h.s = i
h.o = i
i.r = n
i.x = c
i.u = k
i.y = d
m.r = n
m.o = h
m.t = i
assert k.o.r.o.s.x.y.txt == "d"