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

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

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

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

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

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

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