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

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

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

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

a = A("a")
j = B("j")
l = C("l")
d = D("d")
b = C("b")

a.s = l
j.w = d
j.o = b
l.q = j
l.x = d
l.s = d
d.v = l
b.q = j
b.x = d
b.s = d
assert d.v.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

a = A("a")
j = B("j")
l = C("l")
d = D("d")
b = C("b")

a.s = l
j.w = d
j.o = b
l.q = j
l.x = d
l.s = d
d.v = l
b.q = j
b.x = d
b.s = d
assert d.v.q.w.txt == "d"