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

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

h = A("h")
j = B("j")
b = A("b")
k = B("k")

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

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

h = A("h")
j = B("j")
b = A("b")
k = B("k")

h.y = j
j.s = b
b.y = k
k.s = h
assert k.s.y.s.y.txt == "k"