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

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

k = A("k")
i = B("i")
j = A("j")
e = B("e")
a = A("a")
b = B("b")
m = A("m")
g = A("g")

k.w = e
i.q = b
i.x = k
j.w = i
e.q = b
e.x = k
a.w = i
b.q = i
b.x = m
m.w = i
g.w = e
assert a.w.q.x.w.x.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

k = A("k")
i = B("i")
j = A("j")
e = B("e")
a = A("a")
b = B("b")
m = A("m")
g = A("g")

k.w = e
i.q = b
i.x = k
j.w = i
e.q = b
e.x = k
a.w = i
b.q = i
b.x = m
m.w = i
g.w = e
assert a.w.q.x.w.x.w.x.txt == "k"