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

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

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

l = A("l")
n = B("n")
k = C("k")
a = B("a")
g = B("g")
j = C("j")

l.q = g
l.v = g
l.r = j
n.p = l
k.q = l
a.p = l
g.p = l
j.q = l
assert j.q.q.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: B = None
        self.r: C = None
        self.txt = txt

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

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

l = A("l")
n = B("n")
k = C("k")
a = B("a")
g = B("g")
j = C("j")

l.q = g
l.v = g
l.r = j
n.p = l
k.q = l
a.p = l
g.p = l
j.q = l
assert j.q.q.p.r.txt == "j"