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

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

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

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

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

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

n.s = g
b.x = m
m.x = h
h.x = b
g.s = n
assert h.x.x.x.x.x.txt == "m"