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

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

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

b = A("b")
h = B("h")
g = C("g")
e = A("e")
c = B("c")
k = C("k")

b.r = e
b.v = g
h.y = e
h.w = e
h.p = c
g.p = k
g.u = k
e.r = b
e.v = k
c.y = b
c.p = h
c.w = e
k.p = g
k.u = g
assert k.p.p.p.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.v: C = None
        self.txt = txt

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

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

b = A("b")
h = B("h")
g = C("g")
e = A("e")
c = B("c")
k = C("k")

b.r = e
b.v = g
h.y = e
h.w = e
h.p = c
g.p = k
g.u = k
e.r = b
e.v = k
c.y = b
c.p = h
c.w = e
k.p = g
k.u = g
assert k.p.p.p.u.p.txt == "g"