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

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

f = A("f")
h = B("h")
a = A("a")
n = A("n")
c = A("c")
j = A("j")

f.y = c
h.s = f
a.y = n
n.y = j
c.y = f
j.y = n
assert c.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: A = None
        self.txt = txt

f = A("f")
h = B("h")
a = A("a")
n = A("n")
c = A("c")
j = A("j")

f.y = c
h.s = f
a.y = n
n.y = j
c.y = f
j.y = n
assert c.y.y.y.txt == "f"