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

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

i = A("i")
j = B("j")
n = A("n")
k = B("k")
d = B("d")
a = A("a")
c = A("c")
h = B("h")

i.r = k
i.x = c
j.y = i
j.u = i
n.r = j
n.x = i
k.y = i
k.u = c
d.y = n
d.u = c
a.r = h
a.x = i
c.r = d
c.x = n
h.y = c
h.u = c
assert i.r.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.x: A = None
        self.txt = txt

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

i = A("i")
j = B("j")
n = A("n")
k = B("k")
d = B("d")
a = A("a")
c = A("c")
h = B("h")

i.r = k
i.x = c
j.y = i
j.u = i
n.r = j
n.x = i
k.y = i
k.u = c
d.y = n
d.u = c
a.r = h
a.x = i
c.r = d
c.x = n
h.y = c
h.u = c
assert i.r.u.x.txt == "n"