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

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

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

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

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

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

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

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

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

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

n.q = b
b.v = d
b.o = c
b.r = c
b.w = n
d.o = b
d.u = b
d.z = c
d.q = n
c.y = b
c.z = n
c.t = n
assert d.q.q.w.txt == "n"