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

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

h = A("h")
f = B("f")
m = A("m")
j = B("j")

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

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

h = A("h")
f = B("f")
m = A("m")
j = B("j")

h.u = j
f.p = h
f.r = j
m.u = j
j.p = m
j.r = f
assert h.u.r.r.p.txt == "m"