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

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

k = A("k")
g = B("g")
a = A("a")
e = B("e")

k.x = a
k.z = a
g.w = a
a.x = k
a.z = k
e.w = a
assert k.x.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.z: A = None
        self.txt = txt

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

k = A("k")
g = B("g")
a = A("a")
e = B("e")

k.x = a
k.z = a
g.w = a
a.x = k
a.z = k
e.w = a
assert k.x.z.z.txt == "a"