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

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

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

i = A("i")
j = B("j")
f = C("f")
d = C("d")
l = B("l")
e = B("e")
n = B("n")
h = A("h")

i.p = f
i.r = h
j.o = i
f.q = j
f.w = d
f.s = h
d.q = e
d.w = f
d.s = i
l.o = i
e.o = h
n.o = i
h.p = f
h.r = i
assert d.w.q.o.p.w.q.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.r: A = None
        self.txt = txt

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

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

i = A("i")
j = B("j")
f = C("f")
d = C("d")
l = B("l")
e = B("e")
n = B("n")
h = A("h")

i.p = f
i.r = h
j.o = i
f.q = j
f.w = d
f.s = h
d.q = e
d.w = f
d.s = i
l.o = i
e.o = h
n.o = i
h.p = f
h.r = i
assert d.w.q.o.p.w.q.o.p.txt == "f"