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

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

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

j = A("j")
b = B("b")
d = C("d")
a = B("a")
i = B("i")
h = B("h")
k = A("k")
f = A("f")

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

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

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

j = A("j")
b = B("b")
d = C("d")
a = B("a")
i = B("i")
h = B("h")
k = A("k")
f = A("f")

j.q = d
j.y = d
b.x = a
b.r = k
d.p = j
a.x = b
a.r = k
i.x = h
i.r = j
h.x = i
h.r = j
k.q = d
k.y = d
f.q = d
f.y = d
assert i.r.y.p.y.p.y.p.y.txt == "d"