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

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

i = A("i")
k = B("k")
g = A("g")
h = B("h")

i.u = g
i.r = g
k.v = i
k.r = h
g.u = i
g.r = i
h.v = g
h.r = k
assert k.v.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.r: A = None
        self.txt = txt

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

i = A("i")
k = B("k")
g = A("g")
h = B("h")

i.u = g
i.r = g
k.v = i
k.r = h
g.u = i
g.r = i
h.v = g
h.r = k
assert k.v.r.u.txt == "i"