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

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

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

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

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

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

k.u = a
l.y = h
l.x = h
a.u = k
h.y = l
h.x = l
assert l.y.y.x.txt == "h"