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

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

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

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

g = A("g")
c = B("c")
d = C("d")
a = D("a")
b = A("b")
i = C("i")
k = C("k")
h = D("h")
m = A("m")

g.r = h
g.t = a
c.v = b
c.q = h
c.x = k
d.z = g
d.v = c
d.t = h
a.r = m
a.x = g
b.r = h
b.t = a
i.z = g
i.v = c
i.t = a
k.z = g
k.v = c
k.t = a
h.r = b
h.x = g
m.r = h
m.t = a
assert h.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.t: D = None
        self.txt = txt

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

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

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

g = A("g")
c = B("c")
d = C("d")
a = D("a")
b = A("b")
i = C("i")
k = C("k")
h = D("h")
m = A("m")

g.r = h
g.t = a
c.v = b
c.q = h
c.x = k
d.z = g
d.v = c
d.t = h
a.r = m
a.x = g
b.r = h
b.t = a
i.z = g
i.v = c
i.t = a
k.z = g
k.v = c
k.t = a
h.r = b
h.x = g
m.r = h
m.t = a
assert h.r.r.r.txt == "b"