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

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

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

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

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

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

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