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

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

a = A("a")
h = B("h")
n = A("n")
k = B("k")
m = B("m")
b = B("b")
c = A("c")

a.w = c
h.p = m
h.x = k
n.w = a
k.p = h
k.x = m
m.p = k
m.x = k
b.p = k
b.x = h
c.w = a
assert a.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

a = A("a")
h = B("h")
n = A("n")
k = B("k")
m = B("m")
b = B("b")
c = A("c")

a.w = c
h.p = m
h.x = k
n.w = a
k.p = h
k.x = m
m.p = k
m.x = k
b.p = k
b.x = h
c.w = a
assert a.w.w.w.txt == "c"