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

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

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

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

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

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

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