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

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

k = A("k")
h = B("h")
l = B("l")
m = A("m")
n = A("n")

k.r = h
k.p = l
h.w = n
h.o = m
l.w = m
l.o = n
m.r = h
m.p = l
n.r = h
n.p = h
assert h.o.p.o.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: B = None
        self.txt = txt

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

k = A("k")
h = B("h")
l = B("l")
m = A("m")
n = A("n")

k.r = h
k.p = l
h.w = n
h.o = m
l.w = m
l.o = n
m.r = h
m.p = l
n.r = h
n.p = h
assert h.o.p.o.p.w.txt == "n"