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

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

n = A("n")
g = B("g")
e = A("e")
a = B("a")
k = B("k")
j = A("j")
b = A("b")
l = A("l")
h = B("h")

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

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

n = A("n")
g = B("g")
e = A("e")
a = B("a")
k = B("k")
j = A("j")
b = A("b")
l = A("l")
h = B("h")

n.x = l
n.r = b
g.w = a
g.t = b
e.x = j
e.r = j
a.w = g
a.t = j
k.w = h
k.t = j
j.x = n
j.r = b
b.x = e
b.r = n
l.x = n
l.r = j
h.w = a
h.t = e
assert e.r.r.r.x.x.r.r.x.r.txt == "j"