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

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

b = A("b")
h = B("h")
c = B("c")
l = A("l")
i = B("i")
m = A("m")
f = A("f")
a = B("a")

b.x = m
b.o = c
h.s = c
h.w = f
c.s = h
c.w = f
l.x = b
l.o = i
i.s = c
i.w = l
m.x = l
m.o = h
f.x = b
f.o = h
a.s = i
a.w = l
assert f.o.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.o: B = None
        self.txt = txt

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

b = A("b")
h = B("h")
c = B("c")
l = A("l")
i = B("i")
m = A("m")
f = A("f")
a = B("a")

b.x = m
b.o = c
h.s = c
h.w = f
c.s = h
c.w = f
l.x = b
l.o = i
i.s = c
i.w = l
m.x = l
m.o = h
f.x = b
f.o = h
a.s = i
a.w = l
assert f.o.s.w.txt == "f"