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

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

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

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

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

d.r = f
d.v = l
b.o = f
l.x = b
f.p = l
f.w = d
assert f.p.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.v: C = None
        self.txt = txt

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

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

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

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

d.r = f
d.v = l
b.o = f
l.x = b
f.p = l
f.w = d
assert f.p.x.o.txt == "f"