class A:
    def __init__(self, txt: str):
        self.s: 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.s: C = None
        self.x: A = None
        self.txt = txt

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

j = A("j")
m = B("m")
a = C("a")
d = D("d")
i = C("i")

j.s = m
m.r = d
a.s = i
a.x = j
d.s = a
i.s = a
i.x = j
assert i.x.s.r.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: 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.s: C = None
        self.x: A = None
        self.txt = txt

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

j = A("j")
m = B("m")
a = C("a")
d = D("d")
i = C("i")

j.s = m
m.r = d
a.s = i
a.x = j
d.s = a
i.s = a
i.x = j
assert i.x.s.r.s.x.txt == "j"