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.p: B = None
        self.z: B = None
        self.txt = txt

n = A("n")
g = B("g")
j = B("j")
h = A("h")
m = A("m")
b = A("b")

n.p = m
n.x = m
g.p = j
g.z = j
j.p = g
j.z = g
h.p = n
h.x = n
m.p = n
m.x = n
b.p = n
b.x = h
assert m.x.x.p.p.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.p: B = None
        self.z: B = None
        self.txt = txt

n = A("n")
g = B("g")
j = B("j")
h = A("h")
m = A("m")
b = A("b")

n.p = m
n.x = m
g.p = j
g.z = j
j.p = g
j.z = g
h.p = n
h.x = n
m.p = n
m.x = n
b.p = n
b.x = h
assert m.x.x.p.p.txt == "m"