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

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

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

l = A("l")
c = B("c")
b = C("b")
f = C("f")
g = B("g")
m = A("m")

l.x = g
l.t = m
c.r = g
c.s = b
c.o = b
b.v = f
b.p = g
f.v = b
f.p = c
g.r = c
g.s = f
g.o = f
m.x = c
m.t = l
assert b.p.r.r.r.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.t: A = None
        self.txt = txt

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

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

l = A("l")
c = B("c")
b = C("b")
f = C("f")
g = B("g")
m = A("m")

l.x = g
l.t = m
c.r = g
c.s = b
c.o = b
b.v = f
b.p = g
f.v = b
f.p = c
g.r = c
g.s = f
g.o = f
m.x = c
m.t = l
assert b.p.r.r.r.s.p.txt == "g"