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

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

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

h = A("h")
l = B("l")
c = C("c")

h.r = c
l.y = h
c.v = h
assert l.y.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

h = A("h")
l = B("l")
c = C("c")

h.r = c
l.y = h
c.v = h
assert l.y.r.v.txt == "h"