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

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

m = A("m")
n = B("n")
g = B("g")
h = A("h")
a = B("a")
e = A("e")

m.w = h
m.p = n
n.t = h
g.t = h
h.w = m
h.p = n
a.t = m
e.w = m
e.p = a
assert g.t.p.t.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.p: B = None
        self.txt = txt

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

m = A("m")
n = B("n")
g = B("g")
h = A("h")
a = B("a")
e = A("e")

m.w = h
m.p = n
n.t = h
g.t = h
h.w = m
h.p = n
a.t = m
e.w = m
e.p = a
assert g.t.p.t.w.w.w.txt == "m"