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

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

b = A("b")
h = B("h")
n = A("n")
f = B("f")
g = A("g")

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

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

b = A("b")
h = B("h")
n = A("n")
f = B("f")
g = A("g")

b.r = g
h.s = b
n.r = g
f.s = b
g.r = n
assert f.s.r.r.txt == "n"