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

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

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

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

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

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

l.r = h
l.x = a
a.u = j
h.r = l
h.x = j
j.u = a
assert l.x.u.u.u.txt == "j"