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

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

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

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

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

l.w = i
l.p = b
i.q = l
b.r = l
b.o = i
j.s = b
j.q = b
assert l.p.o.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.p: C = None
        self.txt = txt

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

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

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

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

l.w = i
l.p = b
i.q = l
b.r = l
b.o = i
j.s = b
j.q = b
assert l.p.o.q.w.txt == "i"