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

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

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

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

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

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

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