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

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

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

l = A("l")
k = B("k")
d = C("d")
a = B("a")
g = A("g")

l.p = g
l.u = a
k.q = a
d.w = g
d.t = k
a.q = k
g.p = l
g.u = a
assert g.p.p.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.u: B = None
        self.txt = txt

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

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

l = A("l")
k = B("k")
d = C("d")
a = B("a")
g = A("g")

l.p = g
l.u = a
k.q = a
d.w = g
d.t = k
a.q = k
g.p = l
g.u = a
assert g.p.p.u.q.txt == "k"