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

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

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

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

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

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

h.z = e
h.r = a
a.r = c
e.z = h
e.r = i
l.r = c
f.r = l
c.r = a
i.r = a
assert i.r.r.r.r.r.r.txt == "c"