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

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

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

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

i = A("i")
a = B("a")
k = C("k")
l = D("l")

i.x = a
i.s = l
a.v = k
a.x = k
a.s = i
k.r = i
k.w = a
k.s = a
l.r = k
assert i.s.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.s: D = None
        self.txt = txt

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

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

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

i = A("i")
a = B("a")
k = C("k")
l = D("l")

i.x = a
i.s = l
a.v = k
a.x = k
a.s = i
k.r = i
k.w = a
k.s = a
l.r = k
assert i.s.r.r.x.txt == "a"