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

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

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

i = A("i")
h = B("h")
d = C("d")
b = A("b")
g = B("g")
m = A("m")

i.y = b
i.t = m
h.p = d
h.r = g
d.v = i
b.y = i
b.t = i
g.p = d
g.r = h
m.y = b
m.t = b
assert b.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.t: A = None
        self.txt = txt

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

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

i = A("i")
h = B("h")
d = C("d")
b = A("b")
g = B("g")
m = A("m")

i.y = b
i.t = m
h.p = d
h.r = g
d.v = i
b.y = i
b.t = i
g.p = d
g.r = h
m.y = b
m.t = b
assert b.y.y.y.y.y.txt == "i"