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

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

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

class D:
    def __init__(self, txt: str):
        self.q: C = None
        self.u: C = None
        self.txt = txt

b = A("b")
n = B("n")
d = C("d")
m = D("m")

b.s = n
n.s = b
n.y = b
n.z = m
n.o = m
d.v = m
m.q = d
m.u = d
assert m.q.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.q: C = None
        self.u: C = None
        self.txt = txt

b = A("b")
n = B("n")
d = C("d")
m = D("m")

b.s = n
n.s = b
n.y = b
n.z = m
n.o = m
d.v = m
m.q = d
m.u = d
assert m.q.v.u.txt == "d"