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

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

n = A("n")
j = B("j")
c = B("c")
a = A("a")
b = A("b")
f = A("f")

n.r = j
j.r = c
j.x = f
c.r = j
c.x = b
a.r = c
b.r = c
f.r = c
assert f.r.r.x.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

n = A("n")
j = B("j")
c = B("c")
a = A("a")
b = A("b")
f = A("f")

n.r = j
j.r = c
j.x = f
c.r = j
c.x = b
a.r = c
b.r = c
f.r = c
assert f.r.r.x.r.r.x.txt == "f"