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

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

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

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

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

d.x = b
d.p = b
d.y = n
d.z = i
b.w = n
b.y = d
b.p = c
b.o = c
e.x = c
n.o = c
n.r = c
n.z = d
n.p = i
i.o = e
i.r = e
i.z = d
i.p = n
c.x = e
assert n.z.z.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: B = None
        self.y: D = None
        self.z: D = None
        self.txt = txt

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

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

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

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

d.x = b
d.p = b
d.y = n
d.z = i
b.w = n
b.y = d
b.p = c
b.o = c
e.x = c
n.o = c
n.r = c
n.z = d
n.p = i
i.o = e
i.r = e
i.z = d
i.p = n
c.x = e
assert n.z.z.z.x.txt == "b"