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

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

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

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

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

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

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