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

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

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

g = A("g")
i = B("i")
l = C("l")
b = A("b")
f = C("f")
c = C("c")
a = C("a")
d = B("d")
j = A("j")
m = A("m")

g.p = f
g.q = l
i.r = f
l.p = f
b.p = l
b.q = f
f.p = c
c.p = f
a.p = f
d.r = l
j.p = a
j.q = f
m.p = f
m.q = a
assert i.r.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: C = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
l = C("l")
b = A("b")
f = C("f")
c = C("c")
a = C("a")
d = B("d")
j = A("j")
m = A("m")

g.p = f
g.q = l
i.r = f
l.p = f
b.p = l
b.q = f
f.p = c
c.p = f
a.p = f
d.r = l
j.p = a
j.q = f
m.p = f
m.q = a
assert i.r.p.p.p.txt == "c"