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

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

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

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

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

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

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