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

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

a = A("a")
h = B("h")
e = B("e")
c = A("c")
g = A("g")
k = B("k")
d = A("d")
m = B("m")

a.w = k
a.y = g
h.q = e
e.q = m
c.w = k
c.y = d
g.w = e
g.y = a
k.q = m
d.w = m
d.y = c
m.q = k
assert g.y.w.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.y: A = None
        self.txt = txt

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

a = A("a")
h = B("h")
e = B("e")
c = A("c")
g = A("g")
k = B("k")
d = A("d")
m = B("m")

a.w = k
a.y = g
h.q = e
e.q = m
c.w = k
c.y = d
g.w = e
g.y = a
k.q = m
d.w = m
d.y = c
m.q = k
assert g.y.w.q.q.q.txt == "m"