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

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

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

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

g.r = k
k.v = b
k.r = l
k.y = g
l.u = k
b.u = k
assert l.u.v.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

g.r = k
k.v = b
k.r = l
k.y = g
l.u = k
b.u = k
assert l.u.v.u.v.txt == "b"