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

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

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

d = A("d")
n = B("n")
h = C("h")
g = B("g")
j = B("j")
a = C("a")

d.y = n
d.q = n
n.q = h
n.r = j
h.v = j
g.q = h
g.r = n
j.q = h
j.r = g
a.v = j
assert g.r.r.r.q.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

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

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

d = A("d")
n = B("n")
h = C("h")
g = B("g")
j = B("j")
a = C("a")

d.y = n
d.q = n
n.q = h
n.r = j
h.v = j
g.q = h
g.r = n
j.q = h
j.r = g
a.v = j
assert g.r.r.r.q.v.r.txt == "g"