class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.p: C = None
        self.txt = txt

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

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

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

b = A("b")
a = B("a")
m = C("m")
g = D("g")
i = C("i")
c = C("c")
f = B("f")
n = D("n")

b.y = g
b.p = i
a.t = f
a.q = f
a.p = b
a.r = c
m.w = n
m.q = c
m.r = b
m.v = g
g.y = b
g.r = n
i.w = g
i.q = c
i.r = b
i.v = n
c.w = n
c.v = n
c.q = m
c.r = b
f.t = a
f.q = a
f.p = b
f.r = i
n.y = b
n.r = g
assert c.q.v.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.p: C = None
        self.txt = txt

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

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

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

b = A("b")
a = B("a")
m = C("m")
g = D("g")
i = C("i")
c = C("c")
f = B("f")
n = D("n")

b.y = g
b.p = i
a.t = f
a.q = f
a.p = b
a.r = c
m.w = n
m.q = c
m.r = b
m.v = g
g.y = b
g.r = n
i.w = g
i.q = c
i.r = b
i.v = n
c.w = n
c.v = n
c.q = m
c.r = b
f.t = a
f.q = a
f.p = b
f.r = i
n.y = b
n.r = g
assert c.q.v.r.r.txt == "g"