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

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

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

l.u = f
l.p = a
h.u = l
i.u = l
f.u = l
a.u = l
k.u = l
assert h.u.u.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.p: B = None
        self.txt = txt

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

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

l.u = f
l.p = a
h.u = l
i.u = l
f.u = l
a.u = l
k.u = l
assert h.u.u.u.p.u.txt == "l"