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

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

k = A("k")
d = B("d")
g = A("g")

k.w = d
d.q = g
g.w = d
assert g.w.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

k = A("k")
d = B("d")
g = A("g")

k.w = d
d.q = g
g.w = d
assert g.w.q.w.txt == "d"