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

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

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

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

f = A("f")
l = B("l")
g = C("g")
n = D("n")
c = D("c")
d = D("d")
m = B("m")
j = D("j")
b = C("b")
h = A("h")

f.x = n
l.v = b
g.q = c
g.x = l
n.v = d
n.r = l
c.v = n
c.r = l
d.v = j
d.r = l
m.v = g
j.v = c
j.r = m
b.q = c
b.x = l
h.x = d
assert c.v.v.r.v.x.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

f = A("f")
l = B("l")
g = C("g")
n = D("n")
c = D("c")
d = D("d")
m = B("m")
j = D("j")
b = C("b")
h = A("h")

f.x = n
l.v = b
g.q = c
g.x = l
n.v = d
n.r = l
c.v = n
c.r = l
d.v = j
d.r = l
m.v = g
j.v = c
j.r = m
b.q = c
b.x = l
h.x = d
assert c.v.v.r.v.x.v.q.v.txt == "n"