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

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

class C:
    def __init__(self, txt: str):
        self.z: A = None
        self.s: A = None
        self.x: A = None
        self.txt = txt

k = A("k")
l = B("l")
c = C("c")
f = B("f")
n = A("n")

k.t = l
k.p = l
l.q = n
c.z = n
c.x = n
c.s = k
f.q = k
n.t = f
n.p = l
assert k.p.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.p: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: A = None
        self.s: A = None
        self.x: A = None
        self.txt = txt

k = A("k")
l = B("l")
c = C("c")
f = B("f")
n = A("n")

k.t = l
k.p = l
l.q = n
c.z = n
c.x = n
c.s = k
f.q = k
n.t = f
n.p = l
assert k.p.q.p.txt == "l"