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

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

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

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

g = A("g")
e = B("e")
h = C("h")
a = D("a")
b = A("b")
d = A("d")
c = A("c")
j = A("j")
f = C("f")

g.q = b
e.v = c
h.z = e
h.p = f
a.x = c
a.z = c
a.q = j
b.q = j
d.q = c
c.q = d
j.q = b
f.z = e
f.p = h
assert h.z.v.q.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

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

g = A("g")
e = B("e")
h = C("h")
a = D("a")
b = A("b")
d = A("d")
c = A("c")
j = A("j")
f = C("f")

g.q = b
e.v = c
h.z = e
h.p = f
a.x = c
a.z = c
a.q = j
b.q = j
d.q = c
c.q = d
j.q = b
f.z = e
f.p = h
assert h.z.v.q.q.q.q.q.q.q.txt == "d"