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

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

a = A("a")
i = B("i")
l = B("l")
b = A("b")
g = A("g")
f = A("f")

a.w = l
a.z = i
i.q = f
l.q = f
b.w = i
b.z = l
g.w = l
g.z = l
f.w = l
f.z = l
assert a.w.q.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.z: B = None
        self.txt = txt

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

a = A("a")
i = B("i")
l = B("l")
b = A("b")
g = A("g")
f = A("f")

a.w = l
a.z = i
i.q = f
l.q = f
b.w = i
b.z = l
g.w = l
g.z = l
f.w = l
f.z = l
assert a.w.q.w.q.txt == "f"