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

class B:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

f.w = b
b.r = l
k.o = b
l.u = f
l.q = f
l.p = b
assert l.q.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

f.w = b
b.r = l
k.o = b
l.u = f
l.q = f
l.p = b
assert l.q.w.r.txt == "l"