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

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

d = A("d")
h = B("h")
b = A("b")
m = A("m")
c = B("c")
f = A("f")

d.s = f
h.x = d
b.s = f
m.s = d
c.x = b
f.s = d
assert c.x.s.s.s.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.x: A = None
        self.txt = txt

d = A("d")
h = B("h")
b = A("b")
m = A("m")
c = B("c")
f = A("f")

d.s = f
h.x = d
b.s = f
m.s = d
c.x = b
f.s = d
assert c.x.s.s.s.s.s.txt == "f"