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

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

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

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

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

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

h.y = l
l.x = j
j.y = l
k.y = l
assert k.y.x.y.x.txt == "j"