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

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

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

k = A("k")
b = B("b")
l = C("l")
c = B("c")
g = C("g")

k.u = g
b.u = k
b.v = c
b.x = g
l.q = c
l.v = k
c.u = k
c.v = b
c.x = g
g.q = c
g.v = k
assert l.q.x.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

k = A("k")
b = B("b")
l = C("l")
c = B("c")
g = C("g")

k.u = g
b.u = k
b.v = c
b.x = g
l.q = c
l.v = k
c.u = k
c.v = b
c.x = g
g.q = c
g.v = k
assert l.q.x.v.u.txt == "g"