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

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

e = A("e")
k = B("k")
g = A("g")
b = B("b")

e.q = g
e.w = g
k.y = e
k.v = g
g.q = e
g.w = e
b.y = e
b.v = e
assert k.y.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.w: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
g = A("g")
b = B("b")

e.q = g
e.w = g
k.y = e
k.v = g
g.q = e
g.w = e
b.y = e
b.v = e
assert k.y.q.w.txt == "e"