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

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

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

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

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

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

l.u = a
l.p = n
n.r = f
j.u = a
j.p = n
a.u = h
a.p = n
f.r = n
h.u = j
h.p = f
assert f.r.r.r.r.r.r.txt == "f"