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

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

n = A("n")
h = B("h")
l = A("l")
d = B("d")
f = A("f")

n.p = f
n.t = l
h.r = n
h.y = d
l.p = n
l.t = n
d.r = n
d.y = h
f.p = n
f.t = l
assert d.y.y.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.t: A = None
        self.txt = txt

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

n = A("n")
h = B("h")
l = A("l")
d = B("d")
f = A("f")

n.p = f
n.t = l
h.r = n
h.y = d
l.p = n
l.t = n
d.r = n
d.y = h
f.p = n
f.t = l
assert d.y.y.r.p.txt == "f"