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

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

c = A("c")
e = B("e")
j = A("j")
n = A("n")
i = B("i")
h = B("h")
a = B("a")
l = A("l")

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

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

c = A("c")
e = B("e")
j = A("j")
n = A("n")
i = B("i")
h = B("h")
a = B("a")
l = A("l")

c.r = e
e.r = i
e.x = n
j.r = i
n.r = a
i.r = a
i.x = l
h.r = e
h.x = j
a.r = i
a.x = l
l.r = a
assert c.r.x.r.r.txt == "i"