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

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

i = A("i")
c = B("c")
m = A("m")
a = B("a")
g = A("g")
f = A("f")
h = B("h")

i.r = c
c.x = h
m.r = a
a.x = c
g.r = a
f.r = a
h.x = c
assert g.r.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

i = A("i")
c = B("c")
m = A("m")
a = B("a")
g = A("g")
f = A("f")
h = B("h")

i.r = c
c.x = h
m.r = a
a.x = c
g.r = a
f.r = a
h.x = c
assert g.r.x.x.x.txt == "c"