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

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

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

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

c = A("c")
g = B("g")
a = C("a")
b = D("b")
i = B("i")
f = D("f")
k = A("k")
m = A("m")
j = A("j")
e = B("e")

c.u = f
c.r = f
c.y = e
c.x = i
g.z = e
g.r = a
g.p = i
a.u = m
b.q = f
i.z = e
i.r = a
i.p = g
f.q = b
k.u = b
k.r = b
k.y = g
k.x = i
m.u = f
m.y = e
m.x = e
m.r = b
j.u = b
j.r = b
j.y = e
j.x = e
e.z = g
e.r = a
e.p = i
assert b.q.q.q.q.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.y: B = None
        self.r: D = None
        self.x: B = None
        self.txt = txt

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

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

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

c = A("c")
g = B("g")
a = C("a")
b = D("b")
i = B("i")
f = D("f")
k = A("k")
m = A("m")
j = A("j")
e = B("e")

c.u = f
c.r = f
c.y = e
c.x = i
g.z = e
g.r = a
g.p = i
a.u = m
b.q = f
i.z = e
i.r = a
i.p = g
f.q = b
k.u = b
k.r = b
k.y = g
k.x = i
m.u = f
m.y = e
m.x = e
m.r = b
j.u = b
j.r = b
j.y = e
j.x = e
e.z = g
e.r = a
e.p = i
assert b.q.q.q.q.q.q.q.q.q.q.txt == "b"