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

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

class C:
    def __init__(self, txt: str):
        self.z: A = None
        self.s: C = None
        self.txt = txt

b = A("b")
h = B("h")
l = C("l")
e = A("e")
k = C("k")
d = B("d")

b.r = k
h.u = d
h.v = d
h.r = b
l.z = b
l.s = k
e.r = k
k.z = b
k.s = l
d.u = h
d.v = h
d.r = e
assert b.r.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: A = None
        self.s: C = None
        self.txt = txt

b = A("b")
h = B("h")
l = C("l")
e = A("e")
k = C("k")
d = B("d")

b.r = k
h.u = d
h.v = d
h.r = b
l.z = b
l.s = k
e.r = k
k.z = b
k.s = l
d.u = h
d.v = h
d.r = e
assert b.r.s.s.s.s.txt == "k"