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

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

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

f = A("f")
d = B("d")
i = C("i")
h = C("h")
c = C("c")
n = A("n")
g = C("g")
j = A("j")

f.y = j
d.w = j
d.p = i
d.q = n
i.r = h
h.r = c
c.r = g
n.y = j
g.r = c
j.y = n
assert h.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

f = A("f")
d = B("d")
i = C("i")
h = C("h")
c = C("c")
n = A("n")
g = C("g")
j = A("j")

f.y = j
d.w = j
d.p = i
d.q = n
i.r = h
h.r = c
c.r = g
n.y = j
g.r = c
j.y = n
assert h.r.r.r.txt == "c"