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

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

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

g = A("g")
c = B("c")
m = C("m")
f = A("f")
j = B("j")

g.r = f
c.u = j
c.o = j
m.u = g
m.r = f
f.r = g
j.u = c
j.o = c
assert j.o.u.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

g = A("g")
c = B("c")
m = C("m")
f = A("f")
j = B("j")

g.r = f
c.u = j
c.o = j
m.u = g
m.r = f
f.r = g
j.u = c
j.o = c
assert j.o.u.o.txt == "c"