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

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

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

d = A("d")
n = B("n")
i = C("i")
m = C("m")
j = A("j")

d.s = j
n.w = m
i.r = m
i.s = m
m.r = i
m.s = i
j.s = d
assert i.r.s.s.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

d = A("d")
n = B("n")
i = C("i")
m = C("m")
j = A("j")

d.s = j
n.w = m
i.r = m
i.s = m
m.r = i
m.s = i
j.s = d
assert i.r.s.s.r.s.txt == "m"