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

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

k = A("k")
i = B("i")
g = A("g")
n = A("n")
j = B("j")

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

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

k = A("k")
i = B("i")
g = A("g")
n = A("n")
j = B("j")

k.r = i
k.x = i
i.t = k
i.w = j
g.r = i
g.x = i
n.r = j
n.x = j
j.t = n
j.w = i
assert k.r.t.r.txt == "i"