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

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

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

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

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

d.s = i
d.y = j
n.o = j
n.p = i
i.u = d
i.v = d
i.x = n
i.r = n
j.t = n
j.v = d
assert j.v.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.y: D = None
        self.txt = txt

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

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

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

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

d.s = i
d.y = j
n.o = j
n.p = i
i.u = d
i.v = d
i.x = n
i.r = n
j.t = n
j.v = d
assert j.v.y.v.txt == "d"