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

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

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

k.x = d
k.t = g
d.z = i
d.r = k
g.x = i
g.t = k
i.z = d
i.r = k
assert k.t.x.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.t: A = None
        self.txt = txt

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

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

k.x = d
k.t = g
d.z = i
d.r = k
g.x = i
g.t = k
i.z = d
i.r = k
assert k.t.x.z.r.txt == "k"