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

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

h = A("h")
m = B("m")
a = B("a")
e = B("e")
k = A("k")
c = B("c")

h.w = k
m.x = k
a.x = h
e.x = h
k.w = h
c.x = h
assert h.w.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.x: A = None
        self.txt = txt

h = A("h")
m = B("m")
a = B("a")
e = B("e")
k = A("k")
c = B("c")

h.w = k
m.x = k
a.x = h
e.x = h
k.w = h
c.x = h
assert h.w.w.w.w.txt == "h"