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

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

j = A("j")
f = B("f")
g = A("g")
n = B("n")
i = B("i")

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

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

j = A("j")
f = B("f")
g = A("g")
n = B("n")
i = B("i")

j.s = g
f.r = j
g.s = j
n.r = j
i.r = g
assert i.r.s.s.txt == "g"