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

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

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

k = A("k")
a = B("a")
g = C("g")
j = A("j")
b = A("b")

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

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

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

k = A("k")
a = B("a")
g = C("g")
j = A("j")
b = A("b")

k.r = a
k.u = a
k.p = g
a.v = b
g.q = b
g.r = k
j.r = a
j.u = a
j.p = g
b.r = a
b.u = a
b.p = g
assert k.r.v.p.r.txt == "k"