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

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

j = A("j")
g = B("g")
h = A("h")
m = B("m")
a = A("a")
c = A("c")
l = B("l")

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

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

j = A("j")
g = B("g")
h = A("h")
m = B("m")
a = A("a")
c = A("c")
l = B("l")

j.q = g
j.o = c
g.z = l
g.w = a
h.q = l
h.o = c
m.z = g
m.w = j
a.q = g
a.o = j
c.q = g
c.o = a
l.z = m
l.w = a
assert h.q.z.z.w.o.q.txt == "g"