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

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

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

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

b = A("b")
k = B("k")
l = C("l")
j = D("j")

b.y = j
b.q = k
k.o = b
l.v = b
l.w = b
j.w = b
j.o = b
j.p = l
assert j.p.v.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.q: B = None
        self.txt = txt

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

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

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

b = A("b")
k = B("k")
l = C("l")
j = D("j")

b.y = j
b.q = k
k.o = b
l.v = b
l.w = b
j.w = b
j.o = b
j.p = l
assert j.p.v.q.o.txt == "b"