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

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

n = A("n")
f = B("f")
c = A("c")
m = A("m")
j = B("j")
k = B("k")
i = B("i")

n.t = f
f.p = m
f.x = c
c.t = j
m.t = f
j.p = n
j.x = n
k.p = m
k.x = m
i.p = m
i.x = c
assert m.t.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

n = A("n")
f = B("f")
c = A("c")
m = A("m")
j = B("j")
k = B("k")
i = B("i")

n.t = f
f.p = m
f.x = c
c.t = j
m.t = f
j.p = n
j.x = n
k.p = m
k.x = m
i.p = m
i.x = c
assert m.t.p.t.txt == "f"