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

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

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

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

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

d.r = k
b.t = j
n.z = b
n.y = e
k.t = n
k.z = b
k.w = b
k.p = b
e.z = b
e.y = n
j.r = k
h.r = k
assert k.t.z.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

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

d.r = k
b.t = j
n.z = b
n.y = e
k.t = n
k.z = b
k.w = b
k.p = b
e.z = b
e.y = n
j.r = k
h.r = k
assert k.t.z.t.txt == "j"