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

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

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

j = A("j")
i = B("i")
b = C("b")
m = A("m")
g = B("g")
d = C("d")

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

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

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

j = A("j")
i = B("i")
b = C("b")
m = A("m")
g = B("g")
d = C("d")

j.s = m
i.v = g
b.r = i
m.s = j
g.v = i
d.r = i
assert i.v.v.v.v.txt == "i"