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

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

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

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

f = A("f")
g = B("g")
b = C("b")
i = D("i")

f.v = i
f.r = g
g.u = b
b.z = i
b.s = f
i.s = g
i.q = b
i.p = b
assert i.s.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.r: B = None
        self.txt = txt

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

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

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

f = A("f")
g = B("g")
b = C("b")
i = D("i")

f.v = i
f.r = g
g.u = b
b.z = i
b.s = f
i.s = g
i.q = b
i.p = b
assert i.s.u.s.txt == "f"