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

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

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

h.y = j
d.s = b
b.s = d
j.y = f
f.y = j
m.s = b
assert f.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

h.y = j
d.s = b
b.s = d
j.y = f
f.y = j
m.s = b
assert f.y.y.y.y.y.y.txt == "f"