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

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.z: E = None
        self.txt = txt

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

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

class F:
    def __init__(self, txt: str):
        self.x: E = None
        self.p: C = None
        self.y: D = None
        self.txt = txt

f = A("f")
n = B("n")
h = C("h")
g = D("g")
m = E("m")
l = F("l")
j = D("j")
d = C("d")
c = D("c")

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

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.z: E = None
        self.txt = txt

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

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

class F:
    def __init__(self, txt: str):
        self.x: E = None
        self.p: C = None
        self.y: D = None
        self.txt = txt

f = A("f")
n = B("n")
h = C("h")
g = D("g")
m = E("m")
l = F("l")
j = D("j")
d = C("d")
c = D("c")

f.y = n
f.w = l
n.p = m
h.q = n
h.z = m
g.y = l
g.q = h
m.r = d
l.x = m
l.p = h
l.y = g
j.y = l
j.q = h
d.q = n
d.z = m
c.y = l
c.q = h
assert n.p.r.z.r.txt == "d"