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

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

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

class D:
    def __init__(self, txt: str):
        self.s: A = None
        self.t: C = None
        self.y: C = None
        self.txt = txt

d = A("d")
b = B("b")
f = C("f")
n = D("n")
i = A("i")

d.r = n
d.s = f
d.z = b
b.p = n
f.z = n
f.x = n
n.s = d
n.t = f
n.y = f
i.r = n
i.s = f
i.z = b
assert n.y.x.y.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.s: C = None
        self.z: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.s: A = None
        self.t: C = None
        self.y: C = None
        self.txt = txt

d = A("d")
b = B("b")
f = C("f")
n = D("n")
i = A("i")

d.r = n
d.s = f
d.z = b
b.p = n
f.z = n
f.x = n
n.s = d
n.t = f
n.y = f
i.r = n
i.s = f
i.z = b
assert n.y.x.y.z.s.txt == "d"