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

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

h = A("h")
g = B("g")
n = A("n")
a = B("a")
c = A("c")
j = A("j")

h.p = c
h.w = g
g.o = c
n.p = c
n.w = a
a.o = h
c.p = h
c.w = a
j.p = n
j.w = g
assert c.p.p.w.o.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.w: B = None
        self.txt = txt

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

h = A("h")
g = B("g")
n = A("n")
a = B("a")
c = A("c")
j = A("j")

h.p = c
h.w = g
g.o = c
n.p = c
n.w = a
a.o = h
c.p = h
c.w = a
j.p = n
j.w = g
assert c.p.p.w.o.p.p.txt == "h"