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

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

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

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

f = A("f")
i = B("i")
h = C("h")
l = D("l")
m = B("m")
n = B("n")
a = B("a")
k = C("k")
g = C("g")
j = C("j")

f.r = g
i.q = l
i.p = l
h.w = a
h.v = k
h.r = f
l.q = a
m.q = l
m.p = l
n.q = l
n.p = l
a.q = l
a.p = l
k.w = n
k.v = j
k.r = f
g.w = i
g.v = k
g.r = f
j.w = n
j.v = g
j.r = f
assert k.w.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

f = A("f")
i = B("i")
h = C("h")
l = D("l")
m = B("m")
n = B("n")
a = B("a")
k = C("k")
g = C("g")
j = C("j")

f.r = g
i.q = l
i.p = l
h.w = a
h.v = k
h.r = f
l.q = a
m.q = l
m.p = l
n.q = l
n.p = l
a.q = l
a.p = l
k.w = n
k.v = j
k.r = f
g.w = i
g.v = k
g.r = f
j.w = n
j.v = g
j.r = f
assert k.w.q.q.txt == "a"