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

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

h = A("h")
f = B("f")
d = A("d")
m = A("m")
k = A("k")
a = B("a")
n = B("n")
l = B("l")
c = B("c")

h.w = n
h.o = c
f.q = h
d.w = a
d.o = n
m.w = f
m.o = f
k.w = n
k.o = a
a.q = m
n.q = m
l.q = d
c.q = k
assert f.q.w.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.o: B = None
        self.txt = txt

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

h = A("h")
f = B("f")
d = A("d")
m = A("m")
k = A("k")
a = B("a")
n = B("n")
l = B("l")
c = B("c")

h.w = n
h.o = c
f.q = h
d.w = a
d.o = n
m.w = f
m.o = f
k.w = n
k.o = a
a.q = m
n.q = m
l.q = d
c.q = k
assert f.q.w.q.o.txt == "f"