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

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

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

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

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

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

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

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

j.y = b
j.p = f
h.r = c
i.x = a
f.x = a
d.r = g
a.y = b
a.p = f
g.r = d
c.r = h
l.y = j
l.p = i
b.y = a
b.p = i
assert l.y.y.p.x.y.p.x.y.txt == "b"