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

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

n = A("n")
k = B("k")
j = B("j")
m = A("m")
b = A("b")
g = A("g")
d = B("d")
h = B("h")

n.r = b
n.x = m
k.z = g
k.y = g
j.z = b
j.y = g
m.r = n
m.x = n
b.r = g
b.x = g
g.r = b
g.x = b
d.z = b
d.y = m
h.z = m
h.y = n
assert b.r.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.x: A = None
        self.txt = txt

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

n = A("n")
k = B("k")
j = B("j")
m = A("m")
b = A("b")
g = A("g")
d = B("d")
h = B("h")

n.r = b
n.x = m
k.z = g
k.y = g
j.z = b
j.y = g
m.r = n
m.x = n
b.r = g
b.x = g
g.r = b
g.x = b
d.z = b
d.y = m
h.z = m
h.y = n
assert b.r.x.x.x.txt == "b"