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

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

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

g = A("g")
b = B("b")
i = C("i")
d = B("d")
f = A("f")

g.r = i
b.u = d
b.v = g
b.t = i
i.r = d
d.u = b
d.v = f
d.t = i
f.r = i
assert i.r.t.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

g = A("g")
b = B("b")
i = C("i")
d = B("d")
f = A("f")

g.r = i
b.u = d
b.v = g
b.t = i
i.r = d
d.u = b
d.v = f
d.t = i
f.r = i
assert i.r.t.r.u.txt == "b"