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

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

k = A("k")
j = B("j")
h = B("h")
e = A("e")
f = A("f")
g = A("g")
i = A("i")

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

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

k = A("k")
j = B("j")
h = B("h")
e = A("e")
f = A("f")
g = A("g")
i = A("i")

k.w = e
k.x = h
j.q = f
h.q = g
e.w = i
e.x = h
f.w = e
f.x = h
g.w = k
g.x = j
i.w = k
i.x = h
assert e.x.q.w.txt == "k"