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

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

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

i = A("i")
k = B("k")
l = C("l")
j = C("j")
b = A("b")
h = B("h")

i.r = b
k.p = h
k.t = i
l.y = i
j.y = i
b.r = i
h.p = k
h.t = b
assert i.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

i = A("i")
k = B("k")
l = C("l")
j = C("j")
b = A("b")
h = B("h")

i.r = b
k.p = h
k.t = i
l.y = i
j.y = i
b.r = i
h.p = k
h.t = b
assert i.r.r.r.r.r.txt == "b"