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

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

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

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

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

f.r = d
f.w = a
f.v = a
f.p = b
g.q = d
g.t = k
j.p = a
j.z = g
j.t = g
j.s = h
k.q = j
k.v = b
k.t = a
a.r = g
a.w = f
a.v = f
a.p = b
d.q = g
d.t = b
b.q = j
b.v = k
b.t = a
h.p = f
h.z = d
h.t = d
h.s = j
assert a.v.r.t.q.z.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: A = None
        self.v: A = None
        self.p: D = None
        self.txt = txt

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

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

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

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

f.r = d
f.w = a
f.v = a
f.p = b
g.q = d
g.t = k
j.p = a
j.z = g
j.t = g
j.s = h
k.q = j
k.v = b
k.t = a
a.r = g
a.w = f
a.v = f
a.p = b
d.q = g
d.t = b
b.q = j
b.v = k
b.t = a
h.p = f
h.z = d
h.t = d
h.s = j
assert a.v.r.t.q.z.q.q.txt == "g"