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

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.z: D = None
        self.s: D = None
        self.y: D = None
        self.txt = txt

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

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

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

i.q = n
f.p = i
f.z = h
f.s = h
f.y = j
n.r = f
n.q = f
n.x = f
j.p = f
j.y = f
h.p = f
h.y = f
l.r = f
l.q = f
l.x = f
assert n.r.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.z: D = None
        self.s: D = None
        self.y: D = None
        self.txt = txt

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

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

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

i.q = n
f.p = i
f.z = h
f.s = h
f.y = j
n.r = f
n.q = f
n.x = f
j.p = f
j.y = f
h.p = f
h.y = f
l.r = f
l.q = f
l.x = f
assert n.r.s.y.txt == "f"