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

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

g = A("g")
f = B("f")
a = A("a")
i = B("i")
d = B("d")
c = B("c")

g.w = a
g.q = d
f.p = i
f.t = a
a.w = g
a.q = f
i.p = d
i.t = a
d.p = f
d.t = a
c.p = f
c.t = a
assert a.q.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.q: B = None
        self.txt = txt

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

g = A("g")
f = B("f")
a = A("a")
i = B("i")
d = B("d")
c = B("c")

g.w = a
g.q = d
f.p = i
f.t = a
a.w = g
a.q = f
i.p = d
i.t = a
d.p = f
d.t = a
c.p = f
c.t = a
assert a.q.t.q.txt == "f"