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

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

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

b.y = h
a.y = j
h.y = b
m.y = h
j.y = f
f.y = a
assert j.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.y: B = None
        self.txt = txt

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

b.y = h
a.y = j
h.y = b
m.y = h
j.y = f
f.y = a
assert j.y.y.y.y.txt == "f"