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

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

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

k.t = b
k.w = b
g.z = c
g.y = b
c.z = g
c.y = k
b.t = k
b.w = k
assert g.y.w.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.w: A = None
        self.txt = txt

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

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

k.t = b
k.w = b
g.z = c
g.y = b
c.z = g
c.y = k
b.t = k
b.w = k
assert g.y.w.t.w.txt == "k"