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

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

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

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

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

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

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

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

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

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

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