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

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

i = A("i")
k = B("k")
a = A("a")
b = A("b")
g = A("g")
h = B("h")

i.y = b
i.q = b
k.w = g
k.p = h
a.y = b
a.q = g
b.y = a
b.q = i
g.y = a
g.q = a
h.w = g
h.p = k
assert g.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: A = None
        self.txt = txt

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

i = A("i")
k = B("k")
a = A("a")
b = A("b")
g = A("g")
h = B("h")

i.y = b
i.q = b
k.w = g
k.p = h
a.y = b
a.q = g
b.y = a
b.q = i
g.y = a
g.q = a
h.w = g
h.p = k
assert g.q.q.q.txt == "a"