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

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

m = A("m")
e = B("e")
f = A("f")
n = B("n")
l = A("l")
h = A("h")

m.p = f
m.x = f
e.v = n
e.w = h
f.p = l
f.x = h
n.v = e
n.w = m
l.p = f
l.x = h
h.p = m
h.x = f
assert n.w.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.x: A = None
        self.txt = txt

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

m = A("m")
e = B("e")
f = A("f")
n = B("n")
l = A("l")
h = A("h")

m.p = f
m.x = f
e.v = n
e.w = h
f.p = l
f.x = h
n.v = e
n.w = m
l.p = f
l.x = h
h.p = m
h.x = f
assert n.w.x.x.x.txt == "f"