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

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

class C:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: A = None
        self.y: C = None
        self.q: B = None
        self.txt = txt

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

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

d.o = i
d.p = i
d.x = k
d.r = h
i.z = k
h.x = i
h.q = i
h.p = j
h.y = n
k.r = d
n.x = i
n.q = i
n.p = d
n.y = h
j.o = i
j.p = i
j.x = k
j.r = h
assert k.r.r.x.z.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.p: B = None
        self.x: D = None
        self.r: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: A = None
        self.y: C = None
        self.q: B = None
        self.txt = txt

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

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

d.o = i
d.p = i
d.x = k
d.r = h
i.z = k
h.x = i
h.q = i
h.p = j
h.y = n
k.r = d
n.x = i
n.q = i
n.p = d
n.y = h
j.o = i
j.p = i
j.x = k
j.r = h
assert k.r.r.x.z.r.x.txt == "k"